Results 1 to 6 of 6
  1. #1
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121

    Question Run Excel Macro from Access

    I have created a macro file abc.xlsm and save it on my C drive . I want open access form and click on command button to run excel macro.



    What actually I want, I want to open excel file xyz.xlsx and run macro to format my file and close it. End result my xyz.xlsx file should be formatted and close. Below this code just working on abc.xlsm and not on xyz.xlsx.

    Private Sub Command0_Click()
    Dim xl As Object

    Set xl = CreateObject("Excel.Application")
    xl.Workbooks.Open ("C:Workabc.xlsm")
    xl.Visible = True
    xl.Run ("Macro1")
    xl.activeworkbook.Close (True)
    xl.Quit
    Set xl = Nothing
    End Sub

    Help please.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    I am surprised it works at all because the path is missing \ character.

    xlsx workbook cannot have macros. Only xlsm can have macro code.
    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
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by June7 View Post
    I am surprised it works at all because the path is missing \ character.

    xlsx workbook cannot have macros. Only xlsm can have macro code.
    Thank you for your response. Sorry I made a mistake in above.
    Here is code

    Private Sub Command6_Click()
    Dim xl As Object
    Dim xp As Object


    Set xl = CreateObject("Excel.Application" )
    Set xp = CreateObject("Excel.Application" )
    xl.Workbooks.Open (" C:\work\abc.xlsm")
    xp.Workbooks.Open ("C:\work\xyz.xlsx"}



    xl.Visible = True
    xp.Visible = True


    xp.Application.Run ("PERSONAL.XLSB!Macro1")


    xl.ActiveWorkbook.Close (True)
    xp.ActiveWorkbook.close (True)
    xl.Quit
    xp.Quit

    Set xl = Nothing
    Set xp= Nothing

    End Sub

    When I run this code it opens both files abc which contain macro and xyz which i have to format but macro does not run on excel file in fact it does not show macro.


  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    This is something I've never tried to do. So I am somewhat confused.

    If xp is set to xyz.xlsx, why do you reference PERSONAL.XLSB? I have never seen xlsb extension.

    Macro in abc.xlsm is supposed to do something with xyz.xlsx?
    Last edited by June7; 10-11-2015 at 11:29 AM.
    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.

  5. #5
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by June7 View Post
    This is something I've never tried to do. So I am somewhat confused.

    If xp is set to xyz.xlsx, why do you reference PERSONAL.XLSB? I have never seen xlsb extension.

    Macro in abx.xlsm is supposed to do something with xyz.xlsx?
    What will be simple code If I run it from microsoft access form.

    I have created a personal macro on excel workbook to format my end result according to my company format. I save my end result as excel workbook which I export from Access to Excel.
    I want to click on form button to open my excel file which i export every time to be format it as I setup in macro. Simple is that I want to run excel macro from access. Please help me. I hope you understand.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    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. Access macro vs. excel macro
    By twckfa16 in forum Macros
    Replies: 3
    Last Post: 01-07-2015, 03:44 PM
  2. Replies: 3
    Last Post: 10-08-2014, 11:05 AM
  3. Help with excel macro from Access
    By allenjasonbrown@gmail.com in forum Macros
    Replies: 4
    Last Post: 09-18-2013, 12:50 PM
  4. Run Excel macro from Access VBA
    By ragsgold in forum Programming
    Replies: 29
    Last Post: 01-29-2013, 06:55 PM
  5. Replies: 1
    Last Post: 10-15-2010, 06:09 AM

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