fire a excel button click event from vb.net


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: fire a excel button click event from vb.net

  1. #1
    Join Date
    Jan 2007
    Posts
    1

    fire a excel button click event from vb.net

    I need some help!!!

    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! 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

  2. #2
    Join Date
    May 2004
    Location
    Duluth MN
    Posts
    353
    This syntax works for me:

    Code:
        Sub XLTEST(ByVal ProcessFile As String)
            Dim XLApp As New Excel.Application
            Dim XLBook As Excel.Workbook = XLApp.Workbooks.Open(ProcessFile)
            Try
                Dim SheetName As String
                SheetName = "Sheet1"
                XLApp.Visible = True ' for debugging
                XLApp.Run(SheetName & ".CommandButton1_Click")
            Catch ex As Exception
                MsgBox(ex.Message.ToString)
            End Try
            XLBook.Close()
            XLApp.Quit()
            XLBook = Nothing
            XLApp = Nothing
        End Sub

    ...joe

Similar Threads

  1. Replies: 0
    Last Post: 08-26-2005, 04:44 PM
  2. Replies: 0
    Last Post: 12-14-2001, 11:45 AM
  3. Datagrid click event shows wrong row
    By mikeW in forum VB Classic
    Replies: 1
    Last Post: 11-26-2001, 11:28 AM
  4. Button array event handling
    By NING in forum Java
    Replies: 0
    Last Post: 10-05-2001, 04:26 PM
  5. Re: List Boxes? and the Click event
    By Ray Wimsett in forum VB Classic
    Replies: 0
    Last Post: 07-20-2000, 04:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center