Solved

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

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

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.

Question has a verified solution.

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

Suggested Solutions

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

930 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

14 Experts available now in Live!

Get 1:1 Help Now