Results 1 to 5 of 5
  1. #1
    BLUDEV is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    3

    Post MS ACCESS-Running Module to open Excel

    I need help,
    my brain has melted and I hope someone can assist.

    I am trying to run the
    following code as a function in Access 2010:
    Public Function OpenFile()
    Dim xl As Object

    'Step 1: Start Excel, then open the target workbook.
    Set xl = CreateObject("Excel.Application")
    xl.Workbooks.Open ("\\MACSERV8 \Company \Customer Service\ Issues FE File\Data\AMZOrder.xlsm")

    'Step 2: Make Excel visible
    xl.Visible = False



    'Step 3: Run the target macro
    xl.Run "Data_Refresh"
    xl.Run "Clear_Fields"
    xl.Run "Insert_Formula"

    'Step 4: Close and save the workbook, then close Excel
    xl.ActiveWorkbook.Close (True)
    xl.Quit

    'Step 5: Memory Clean up.
    Set xl = Nothing
    End Function
    When I try to call it out, it gives me the
    following error:
    "Run-time error '1004': The macro may not be available in
    this workbook or all macros may be disabled"

    Yet, when I run the code in
    Excel, it works perfectly. Please help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    Comment says "Make Excel visible" yet code makes it not visible.

    Is the Excel code in a general module?

    I put Excel code in a general module in the workbook and set Access code Visible to True. Works.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    BLUDEV is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    3
    June7, thank you so much, it did open but now another error occurred. For some reason, when it goes to open Excel, the "DataLink Properties" dialogue box opens up and stops the macro's I have tied to the Excel file from running, when I click "OK" in the dialogue boxes (see attachments) it tells me it can't find the database. It's like the Excel sheet won't run the macros with Excel open. Is there a way around this?

  4. #4
    BLUDEV is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    3
    June7, sorry, attachments wouldn't append.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    Don't know, the code worked with the edits.

    Should append - did you zip files?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. create excel module/macro with access vba
    By trevor40 in forum Programming
    Replies: 3
    Last Post: 02-01-2015, 08:55 PM
  2. Replies: 6
    Last Post: 10-17-2014, 09:38 AM
  3. Replies: 4
    Last Post: 03-13-2013, 08:57 PM
  4. Converting Excel Macro into Access Module
    By diddyville in forum Modules
    Replies: 1
    Last Post: 03-28-2011, 07:02 PM
  5. Running a module
    By KevinMCB in forum Modules
    Replies: 2
    Last Post: 03-09-2011, 02:38 PM

Tags for this Thread

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