fire a excel button click event from vb.net
I am trying to call a commandbutton1_click() sub defined in excel from vb. I need to process any of the incoming excel files and have the vb application behave like someone were pushing the button...
I thought I could call it like I would call an excel macro.. but its saying Macro not found! :confused: This is what I have so far
Sub ProcessFiles(ByVal ProcessFile As String)
Dim XLApp As Object
Dim XLBook As Object
Dim VBComp As Object
Dim SheetName As String
SheetName = "'Sheet1$'"
XLApp = CreateObject("Excel.Application")
XLBook = XLApp.workbooks.open(ProcessFile)
XLApp.run(ProcessFile & "!" & SheetName & "!CommandButton1.Click()")
VBComp = XLBook.VBProject.VBComponents("Module1")
XLBook.VBProject.VBComponents.Remove(VBComp)
VBComp = Nothing
XLBook.Save()
XLApp.Quit()
XLBook = Nothing
XLApp = Nothing
End Sub
Any help is greatly appreciated.
Thank you

