Link to home
Start Free TrialLog in
Avatar of Stephen Byrom
Stephen ByromFlag for Ireland

asked on

Rune macro in Excel from Access

HI,
I am trying to run a macro in an Excel workbook from within Access, using a button on an Access form. Can someone help me in finding out why the following code doesn't work?
'set variables to open Excel
    Dim objXL As Excel.Application
    Dim objWkb As Excel.Workbook
    Dim objSht As Excel.Worksheet
    Dim strFileName As String

strFileName = (GetMyPath() & "Interface2.xlsm")
    Set objXL = New Excel.Application
    With objXL
        Set objWkb = .Workbooks.Open(strFileName, , False, , "thisisthepassword")
                For Each objSht In objWkb.Worksheets
                    objSht.Visible = xlSheetVisible
                Next objSht
                objWkb.Run "Upload2Dbase"
        Set objSht = objWkb.Worksheets("SageDump")
        .Visible = True
        AppActivate objXL.Caption
        objSht.Activate
     End With
     
    'destroy objects
    Set objSht = Nothing
    Set objWkb = Nothing
    Set objXL = Nothing

Open in new window

The error I get is that the Object doesn't support this property or method.
I have searched google and this site for pointers but I'm at a loss.
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stephen Byrom

ASKER

Beautifully simple.
Thanks