Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to run a macro (in personal.xls) whatever file (in the listing) open

I have a macro in personal.xls. I want the macro in personal.xls to
execute whenever a file is open. Based on the filename, i will further
execute certain commands.

The filename that fit the criteria is listed in personal.xls as well.

regards

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to run a macro (in personal.xls) whatever file (in the listing)open

You'll need an application event that monitors when you open another workbook.

Put this in your personal.xls's project under the ThisWorkbook module.

You may have to modify your workbook_open event to include the code--you'll want
to merge the code into one procedu

Option Explicit
Public WithEvents xlApp As Excel.Application
Private Sub Workbook_Open()
Set xlApp = Application
End Sub
Private Sub Workbook_Close()
Set xlApp = Nothing
End Sub
Private Sub xlApp_WorkbookOpen(ByVal Wb As Workbook)

Select Case LCase(Wb.Name)
Case Is = "book1.xls", "book2.xls"
Case Else
Exit Sub
End Select

Call YourMacroHere(Wb.Name)

End Sub

And I had this in a general module in my personal.xls workbook.

Option Explicit
Sub YourMacroHere(myName As String)
MsgBox myName
End Sub

You can read a lot more about application events at Chip Pearson's site:
http://www.cpearson.com/excel/AppEvent.htm

" wrote:

I have a macro in personal.xls. I want the macro in personal.xls to
execute whenever a file is open. Based on the filename, i will further
execute certain commands.

The filename that fit the criteria is listed in personal.xls as well.

regards


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Personal Macro Workbook buumoon Excel Discussion (Misc queries) 1 January 31st 06 03:08 PM
shortcut to open file in personal.xls blocking file's macros No Name Excel Programming 1 June 14th 05 01:08 AM
Macro trying to open second Personal? Ed Excel Programming 8 January 27th 05 09:17 PM
How do I get my personal macro worksheet to open whenever I open . Claudia_R Excel Discussion (Misc queries) 3 December 9th 04 11:59 PM
personal.xls doesn't open when double-clicking on Excel file Tom Excel Programming 4 November 5th 04 01:42 AM


All times are GMT +1. The time now is 05:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"