Solved

Access running a Excel personal macro

Posted on 2013-06-18
2
1,506 Views
Last Modified: 2013-06-18
Hello Experts,

Hoping someone can help me.

I have Access 2007 and using a VBA script to:

1.  Export sales data to an Excel sheet to drive c:\SalesUpdateNew.xlsx
2.  Open PERSONAL.XLSB, which contains the macros I need to run in SalesUpdateNew.xlsx

THe VBA is opening the PERSONAL.XLSB and SalesUpdateNew.xlsx but failing to run the PERSONAL.XLSB macro in SalesUpdateNew.xlsx.

When run using the VBA the macros don't show in "All open Workbooks" in the SalesUpdateNew.xlsx workbook". They do show in PERSONAL.XLSB.   When I manually open SalesUpdateNew.xlsx, it works. What am I missing in my code?

Private Sub Command0_Click()
Dim x2 As Object
Dim x3 As Object


DoCmd.RunMacro "Export Sales Update2"   ' Export sales data excel workbook (SalesUpdateNew.xlsx) to c:\

       
    Call WaitFor(5) ' Wait 5 seconds
       Set x2 = CreateObject("Excel.Application")
       x2.Workbooks.Open ("C:\Documents and Settings\USER\Application Data\Microsoft\Excel\XLSTART\PERSONAL.XLSB")
       x2.Visible = True
        
    Call WaitFor(5) ' Wait 5 seconds
      Set x3 = CreateObject("Excel.Application")
       x3.Workbooks.Open ("C:\SalesUpdateNew.xlsx")
       x3.Visible = True
       x3.Application.Run "Personal.xlsb:SalesUpdate"

End Sub

Open in new window


Thanks!
0
Comment
Question by:CompTech810
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 200 total points
ID: 39256629
You're running different instances of Excel so personal.xlsb is not available in the second one. Try this:
Private Sub Command0_Click()
Dim x2 As Object
Dim x3 As Object


DoCmd.RunMacro "Export Sales Update2"   ' Export sales data excel workbook (SalesUpdateNew.xlsx) to c:\

       
    Call WaitFor(5) ' Wait 5 seconds
       Set x2 = CreateObject("Excel.Application")
       x2.Workbooks.Open ("C:\Documents and Settings\USER\Application Data\Microsoft\Excel\XLSTART\PERSONAL.XLSB")
       x2.Visible = True
        
    Call WaitFor(5) ' Wait 5 seconds
       x2.Workbooks.Open "C:\SalesUpdateNew.xlsx"
       x2.Run "Personal.xlsb!SalesUpdate"

End Sub

Open in new window

0
 
LVL 2

Author Closing Comment

by:CompTech810
ID: 39256662
Thanks!!  Worked!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

914 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

23 Experts available now in Live!

Get 1:1 Help Now