i need to play macro on Excel by visual basic 6 RRS feed

  • Question

  • I need to play macro on Excel bay visual basic 6

    and open my file.xlsb because open my VBA App

    -this app open after excel workbook in windows a duple click 

    -my office is 2007

    Tuesday, March 28, 2017 2:46 PM

All replies

  • You have to use Excel Automation:

            Dim oExcel As Object
            Dim oBook As Object
            Dim oBooks As Object
            'Start Excel and open the workbook.
            Set oExcel = CreateObject("Excel.Application")
            oExcel.Visible = True
            Set oBooks = oExcel.Workbooks
            Set oBook = oBooks.Open("C:\Users\username\Documents\WorkbookName.xlsx")
            'Run the macros.
            oExcel.Run "DoKbTest"
            oExcel.Run "DoKbTestWithParameter", "Hello from VB Client"
            'Clean-up: Close the workbook and quit Excel.
            oBook.Close SaveChanges:=False
            Set oBook = Nothing
            Set oBooks = Nothing
            Set oExcel = Nothing

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, March 29, 2017 12:47 PM