Solved

Use VBA to Open Excel file and Run Excel Macro, Can't get it to work.

Posted on 2007-03-20
4
1,171 Views
Last Modified: 2013-11-27
I am attempting to open an Excel file via Access VBA and then run an Excel Macro.
I have the code and have looked in the knowledgebase for similar solutions, however for some reason the VBA errors on the line where the Excel Macro is to be run, stating "Run-time error 438: Object doesn't support this property or method."

Am I missing something obvious OR is this related to the MS lawsuit where certain things relating to Excel functionality were eliminating??

Here's my code:
    Dim objXL As Object
    Dim objWB As Object
     
    Set objXL = CreateObject("Excel.Application")
   
    'To open existing workbook
    Set objWB = objXL.Workbooks.Open("C:\PaulChesenData\ExcelImport1.xls")
   
    objWB.Run ("ExcelImport1.xls!TestData.UpdateLookupData")

    'CLOSE DOWN
    objWB.Close
    objXL.Quit
    Set objWB = Nothing
    Set objXL = Nothing

The code fails on this line:
   objWB.Run ("ExcelImport1.xls!TestData.UpdateLookupData")
I've tried several variations of referencing the Macro, but none have worked including:
     objWB.Run ("ExcelImport1.xls!TestData.UpdateLookupData")
     objWB.Run ("TestData!UpdateLookupData")
     objWB.Run ("UpdateLookupData")

The filename is ExcelImport1.xls, the worksheet with the Macro is "TestData" and the Macroname is "UpdateLookupData"

Thanks,
0
Comment
Question by:bkapla1
  • 3
4 Comments
 

Author Comment

by:bkapla1
ID: 18756306
Woops, I got it to work.

I had an OnError code including for error handling, but I wasn't paying attention and added this code further down in the code rather than in the beginning.

I moved it to the beginning of the code and the VBA now runs as expected.

0
 

Author Comment

by:bkapla1
ID: 18756355
Ok, Woops again... all that did was make the error go to the handler, which I didn't include an error message, so it just erred silently... it's one of those mornings.

So, the error is still valid and I still need help!
0
 

Author Comment

by:bkapla1
ID: 18756392
Ok, got it for real this time!

I change this line from this:
objWB.Run ("TestData!UpdateLookupData")

TO this:
objXL.Run ("UpdateLookupData")

and it worked!

Phew!!!
0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
ID: 18894818
bkapla1,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question