Open Excel from Access Command and auto_open macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mld01s
    New Member
    • Sep 2008
    • 5

    #1

    Open Excel from Access Command and auto_open macro

    Hi all!!

    I need help, I have been stuck for a few days on this one. I am trying to open an excel table from a command button in Access. The excel table has an auto_open macro, that is supposed to run everytime I open excel.
    When I navigate to the excel file, and open it, it autoruns the macro with no problems. When I go from Access hit the command, the excel table opens with no problem, but the macro does not auto run on start.
    Here is the code I used to open my Excel table:

    Dim appExcel As Object
    Dim myWorkbook As Object
    Set appExcel = CreateObject("E xcel.Applicatio n")
    Set myWorkbook = appExcel.Workbo oks.Open("R:\Ra ilTrace (Mauricio)\DBs\ Rail Trace\MapExcelD ata.xls")
    appExcel.Visibl e = True
    Set appExcel = Nothing
    Set myWorkbook = Nothing

    Thank you in advance for your help.
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    Are you using Office 2007? I am and it worked with code very similar to yours.

    Dim appExcel As Object
    Set appExcel = CreateObject("E xcel.Applicatio n")
    appExcel.workbo oks.Open "C:\ExcelVBA.xl s"
    appExcel.Visibl e = True

    However, it didn't run the Workbook_Open() until I set my macro permissions and trusted the location of the file.

    Comment

    • mld01s
      New Member
      • Sep 2008
      • 5

      #3
      ChipR,

      Im working with excel 2003 and access 2000. Earlier I made it work running one command. I wrote a batch file to open my excel table, and I open the batch by running the command. It is working now, but I still want to figure out the other way.
      Did you setup your securty for macros at low? (because I tried that and it didn't work) or did you put it at high and added a digital signature?? (which I didnt try because im not to sure how to do it)

      Thanks for your response...

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        Actually, in 2007 I didn't have an option for low, so I had to just enable all macros for now.
        :(

        Comment

        • Nick from Sussex
          New Member
          • Feb 2009
          • 1

          #5
          Use the Application.Run command

          Here would be how to do it in your code:

          Dim appExcel As Object
          Dim myWorkbook As Object
          Set appExcel = CreateObject("E xcel.Applicatio n")
          Set myWorkbook = appExcel.Workbo oks.Open("R:\Ra ilTrace (Mauricio)\DBs\ Rail Trace\MapExcelD ata.xls")

          appExcel.Run "Auto_Open" '<---------Here it is !!!

          appExcel.Visibl e = True
          Set appExcel = Nothing
          Set myWorkbook = Nothing

          Comment

          Working...