Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Execute Excel Macro from Template

Status
Not open for further replies.

grannyM

Programmer
Nov 26, 2002
39
US
I'm new to writing macros in Excel. In Word if you have a template on the General Tab under File/New, it will automatically execute when you double-click on the icon. How do you get an Excel Macro on a template to excute from the General Tab under File/New? When I double-click on the icon it will only open the template, not execute the macro.
 
You need to call the macro from the workbook's Open() event:

Code:
'@---------- Workbook Module ------------@

Private Sub Workbook_Open()
  Call GetFileName
End Sub



'@-------------- Module 1 ---------------@

'Macros

Sub GetFileName()
  Dim strTitle As String
  
  strTitle = InputBox("Enter Workbook Name:", "Title", "")
  
  If Len(strTitle) > 0 Then
    ActiveWorkbook.SaveAs strTitle & ".xls"
  End If
End Sub
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
It worked! It was almost one of those "Duh, I should have known that" questions, so I really appreciate your response. Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top