Open Excel Workbook and run macro stored in Personal.xls

Nokose

New Member
Joined
Feb 13, 2009
Messages
23
I am working on email an excel report out. I need to format the report before it is sent. I have created a macro in my personal workbook. I would like access to be able to open the report use the macro form the personal book and then save it. SO far I am stumped. Here is what I have so far:

Dim appXL As Excel.Application
Dim wbk As Excel.Workbook

Set appXL = New Excel.Application

Set wbk = appXL.Workbooks.Open("s:\hris\badge report\Daily Badge Number Check.xls")

appXL.Run wbk.PERSONAL.XLS & "!BadgeNumber"
wbk.Close True
appXL.Quit

Any help would be appreciated.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
1. You don't want to assume personal.xls is open (but it might be....not sure if the startup would ignore opening personal.xls if programmatically opened)...

2. Also, need to change the syntax to run the macro...

Code:
Dim appXL As Excel.Application
Dim wbk As Excel.Workbook

Set appXL = New Excel.Application

Set wbk = appXL.Workbooks.Open("s:\hris\badge report\Daily Badge Number Check.xls")

[COLOR="SeaGreen"]'//Make sure personal.xls is open[/COLOR]
[COLOR="Blue"]On Error Resume Next
varTemp = Workbooks("PERSONAL.xls").Name
If Err Then
Workbooks.Open ("C:\folder\folder\PERSONAL.xls")
End if
On Error Goto 0[/COLOR]

appXL.Run ("PERSONAL.xls!BadgeNumber")
wbk.Close True

appXL.Quit

Not tested....
Edit: And of course substitute the real full path to your Personal.xls - not my folder\folder stuff
 
Upvote 0
The script is workig and calling the macro. Thank you.

Now it is leading to another issue. I have tried to find it in Excel but am unable to. Here is the issue.

When it runs this macro and it tries to close and save it I get a box saying it is an older format and if I want to save and overwrite it. Of course I do. Then it comes up with another box asking if I want to save the clipboard. Anyone know how to get these two prompts to clear out automatically? Any help is appreciated.
 
Upvote 0
The first message...not sure...seems like it should go away after you say yes...try to get the workbooks all in the same format is my advice (if this is possible)

The second, you probably have copied something in your macro that you run and the data is on the clipboard. Try putting this line:

Application.CutCopyMode = False

At the end of the macro "BadgeNumber"
 
Upvote 0
I will try the False. The report format comes from Access. Access creates the excel book froma query before it is formatted. What is the code for the most recent format form Access?
 
Upvote 0
I have got it all to work. The code below opened excel ran a macro stored in the Personal WOrkbook and then shut it down overwrtiing the file and disregarding any other warnings that pop up. Hope this helps someone else.

Private Sub Form_Open(Cancel As Integer)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
DoCmd.OutputTo acOutputQuery, "Badge Change", "MicrosoftExcelBiff8(*.xls)", "s:\hris\badge report\Daily Badge Number Check.xls"<o:p></o:p>
<o:p></o:p>
Dim appXL As Excel.Application<o:p></o:p>
Dim wbk As Excel.Workbook<o:p></o:p>
<o:p></o:p>
Set appXL = New Excel.Application<o:p></o:p>
<o:p></o:p>
Set wbk = appXL.Workbooks.Open("s:\hris\badge report\Daily Badge Number Check.xls")<o:p></o:p>
<o:p></o:p>
'//Make sure personal.xls is open<o:p></o:p>
On Error Resume Next<o:p></o:p>
varTemp = Workbooks("PERSONAL.xls").Name<o:p></o:p>
If Err Then<o:p></o:p>
Workbooks.Open ("C:\Documents and Settings\tibbja\Application Data\Microsoft\Excel\XLSTART\PERSONAL.xls")<o:p></o:p>
End If<o:p></o:p>
On Error GoTo 0<o:p></o:p>
<o:p></o:p>
appXL.Run ("PERSONAL.xls!BadgeReport")<o:p></o:p>
Excel.Application.DisplayAlerts = False<o:p></o:p>
<o:p></o:p>
wbk.Close True<o:p></o:p>
<o:p></o:p>
appXL.Quit

<o:p></o:p>
 
Upvote 0
Thanks for sharing your experience.

Keep Excelling!
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,060
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top