Share via

Detect when template opened as NEW.

Anonymous
2012-04-09T18:53:52+00:00

I know that when a template xltm file is opened as New, Excel will change the name to template1 and because I have macros defined the file format to xlOpenXMLWorkbookMacroEnabled. I would like to have some VBA macros to do some things when the file is first opened as New template. I know that the Workbook_Open or Auto_open macros run on open, but I can't figure out how to detect if this is the template New Open.

I thought of one of the following would enable me to do this:

  1. Is there a built in way to detect when a template *.xltm file is first opened as New?
  2. I thought of putting something in a cell in a worksheet and then having the Auto_open or Workbook_Open code change it if the fileformat is not a template. But this seemed like a kludge.

Any other options?

Thanks

John

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-04-09T20:24:35+00:00
A saved workbook will have a <br>path.
An unsaved workbook will not.
Check for the path and Exit Sub if<br>path is found.
If not, carry on with workbook_open code.
Private Sub Workbook_Open()
If ActiveWorkbook.Path <> "" Then Exit Sub
'your code here
End Sub

Gord

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-04-09T21:16:09+00:00

    Perfect!!

    Thanks,

    John

    Was this answer helpful?

    0 comments No comments