Results 1 to 2 of 2
  1. #1
    drhayes is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    1

    Errors While Trying to Run an Excel Macro from Access

    I've been struggling with this problem for hours.



    I've used transfer spreadshet to create the Test.xlsx file which I want to run a macro on. The Macro is called ShortFinishedAA. Every time I run it it says that "Cannot run the macro Test.xls!ShortFinishedAA the macro may not be available in this workbook or all macros may be disabled." When I go to the already opened excel file I notice that if you manually try to run the macro you find that there aren't any. Essentially, I think the Personal macro workbook I have Isn't loading even though it loads every other time I open an excel file.

    Is there a way to load the personal macro workbook in this code? And then run the macro? Or is there a better way to do all of this?

    Code:
    strFile = "Test.xlsx"
    strMacro = "ShortFinishedAA"
    Set xls = CreateObject("Excel.Application")
    xls.Visible = True
    Set xwkb = xls.Workbooks.Open("C:\Users\Danny\Desktop\CCFP\Client Accounts Data\Asset Allocations Daily Data\" & strFile)
    xls.Run strFile & "!" & strMacro
    xwkb.Close False
    Set xwkb = Nothing
    xls.Quit
    Set xls = Nothing
    
    End Function

  2. #2
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Try using the RunMacro Event instead of bang notation:

    Replace:
    Code:
    xls.Run strFile & "!" & strMacro
    With:
    Code:
    xls.RunMacro strMacro, ,

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 07-25-2011, 12:07 PM
  2. Running excel macro from access
    By timpepu in forum Programming
    Replies: 1
    Last Post: 02-26-2010, 11:32 PM
  3. Write Conflict Errors with SQL-Access DB
    By trb5016 in forum Access
    Replies: 5
    Last Post: 01-14-2010, 02:10 PM
  4. Convert Excel Macro to Access Query
    By crownedzero in forum Queries
    Replies: 1
    Last Post: 06-22-2009, 02:13 PM
  5. Replies: 0
    Last Post: 05-07-2009, 02:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums