ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Auto New macros? (https://www.excelbanter.com/excel-programming/307739-auto-new-macros.html)

Christine[_6_]

Auto New macros?
 
Excel Help says "Automatic macros, such as Auto_Open, are
designed to run when you start Excel. For more information
about these macros, see Microsoft Visual Basic Help."

When I look in VB Help, however, I can't find any
reference to automatic macros.

What I need is the code for a macro to run automatically
whenever a user creates a new workbook based on my
template. The template is protected so the user can only
enter data in specific cells.

I presently have the following macro:

Sub Auto_New()

With ActiveWindow
.DisplayHeadings = False
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
.DisplayWorkbookTabs = False
End With
End Sub

The macro will not run unless you specifically select
Tools, Macro, Run... etc., which obviously defeats the
point!

Can someone give me a really quick response?

Cheers,
Christine

Tom Ogilvy

Auto New macros?
 
Put you macro in the Workbook_Open event and you can restrict it to creation
with code like

if thisworkbook.path = "" then
' the workbook has just been created

End if

before a workbook is saved, it doesn't have a path, so this would indicate
it was just created with your template.

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy

"Christine" wrote in message
...
Excel Help says "Automatic macros, such as Auto_Open, are
designed to run when you start Excel. For more information
about these macros, see Microsoft Visual Basic Help."

When I look in VB Help, however, I can't find any
reference to automatic macros.

What I need is the code for a macro to run automatically
whenever a user creates a new workbook based on my
template. The template is protected so the user can only
enter data in specific cells.

I presently have the following macro:

Sub Auto_New()

With ActiveWindow
.DisplayHeadings = False
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
.DisplayWorkbookTabs = False
End With
End Sub

The macro will not run unless you specifically select
Tools, Macro, Run... etc., which obviously defeats the
point!

Can someone give me a really quick response?

Cheers,
Christine




Frank Stone

Auto New macros?
 
use the workbook_ Open() event.
Autorun macro
Private Sub Workbook_Open()
your code
End Sub

-----Original Message-----
Excel Help says "Automatic macros, such as Auto_Open, are
designed to run when you start Excel. For more

information
about these macros, see Microsoft Visual Basic Help."

When I look in VB Help, however, I can't find any
reference to automatic macros.

What I need is the code for a macro to run automatically
whenever a user creates a new workbook based on my
template. The template is protected so the user can only
enter data in specific cells.

I presently have the following macro:

Sub Auto_New()

With ActiveWindow
.DisplayHeadings = False
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
.DisplayWorkbookTabs = False
End With
End Sub

The macro will not run unless you specifically select
Tools, Macro, Run... etc., which obviously defeats the
point!

Can someone give me a really quick response?

Cheers,
Christine
.



All times are GMT +1. The time now is 10:32 AM.

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