Solved

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

Posted on 2007-03-20
4
1,162 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now