startup macro on condition of filename

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Please suggest how to use the startup macro when the filename was open
eg.: when I open report.xls the macro should be autorun but the other files was open the macro notrun
thanks,
 
arun,

I'm a little confused from your post.

To run a macro when a workbook opens, you can name the sub Auto_Open

Sub Auto_Open()
' your code
End Sub

The above will automatically run whenever the workbook that it's contained
within
is opened.

If you're looking to run a particular macro when the workbook is opened from
another workbook only, use the Application.Run function from the original
workbook.

Workbooks.Open Filename:="FileName.xls"
Application.Run "'FileName.xls'!MacroName"

John

arun said:
Please suggest how to use the startup macro when the filename was open ?
eg.: when I open report.xls the macro should be autorun but the other
files was open the macro notrun.
 
I just got done doing this.. I created a class event inside a addin and then
followed Chip Pearson's advice:

You need to use application events to trap for workbook being
opened. See www.cpearson.com/excel/appevent.htm for more details.

I altered the workbook_open event to continue to execute if the wb.name was
correct. I found out later I coded it case-sensitive.




arun said:
Please suggest how to use the startup macro when the filename was open ?
eg.: when I open report.xls the macro should be autorun but the other
files was open the macro notrun.
 
Back
Top