ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   auto_open macro (https://www.excelbanter.com/excel-programming/368325-auto_open-macro.html)

travis

auto_open macro
 
I have a macro that runs everytime I open a new book after it is ran the
first time. I have to close Excel to open a new book without it running.
What is causing this problem? I've tried changing the name of the macro
without "auto_open".

Sub Change()

Application.OnWindow = "Restore_menus"

Application.Windows("test2.xls").OnWindow = "Disable_menu"

End Sub

Tom Ogilvy

auto_open macro
 
I am guessing Change the macro that was named Auto_Open.

In any event, I would say that

Application.OnWindow
sets an application level event.

So anytime a window is activated (such as opening a new workbook) that Macro
(Restore_Menus) will be run.

If you want it workbook level, perhaps then

Application.Windows("test2.xls").OnWindow = "Restore_menus"

rather than

Application.OnWindow = "Restore_menus"

--
Regards,
Tom Ogilvy


"travis" wrote:

I have a macro that runs everytime I open a new book after it is ran the
first time. I have to close Excel to open a new book without it running.
What is causing this problem? I've tried changing the name of the macro
without "auto_open".

Sub Change()

Application.OnWindow = "Restore_menus"

Application.Windows("test2.xls").OnWindow = "Disable_menu"

End Sub


travis

auto_open macro
 
Thank you, Tom.

Yes, at one point the macro was named "Auto_Open", I thought maybe that was
the problem. It wasn't. This was very helpful.

Travis

"Tom Ogilvy" wrote:

I am guessing Change the macro that was named Auto_Open.

In any event, I would say that

Application.OnWindow
sets an application level event.

So anytime a window is activated (such as opening a new workbook) that Macro
(Restore_Menus) will be run.

If you want it workbook level, perhaps then

Application.Windows("test2.xls").OnWindow = "Restore_menus"

rather than

Application.OnWindow = "Restore_menus"

--
Regards,
Tom Ogilvy


"travis" wrote:

I have a macro that runs everytime I open a new book after it is ran the
first time. I have to close Excel to open a new book without it running.
What is causing this problem? I've tried changing the name of the macro
without "auto_open".

Sub Change()

Application.OnWindow = "Restore_menus"

Application.Windows("test2.xls").OnWindow = "Disable_menu"

End Sub



All times are GMT +1. The time now is 03:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com