Solved

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

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

809 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