Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-03-20
4
Medium Priority
?
1,185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

596 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