O
Orion Cochrane
I have a template that is an application that saves the template as a
pre-defined name format. It is also supposed to remove the Workbook_Open
macro from the newly saved workbook. Here is the code:
Private Sub Workbook_Open()
'Saves template with standard filename
Dim myPath As String, myFile As String, myExt As String
myPath = "Path"
myFile = "Constant " & Format(Date, "MMMM DD, YYYY")
myExt = ".xls"
If ActiveWorkbook.Name <> "Template.xls" Then _
ActiveWorkbook.VBProject.VBComponents.VBE.ActiveCodePane.CodeModule.DeleteLines 1, 11
If ActiveWorkbook.Name = "Template.xls" Then _
ActiveWorkbook.SaveAs Filename:=myPath & myFile & myExt
End Sub
Where it hangs up is where the workbook name <> "Template.xls". When I open
the new file and manually run the code (F5), it works. I get an "Object
Variable or With not defined" error. I tried adding a Call Workbook_Open line
before End Sub, and it still hung up. Is the active workbook still the
Template? How can I make sure that the active workbook is the newly saved one?
pre-defined name format. It is also supposed to remove the Workbook_Open
macro from the newly saved workbook. Here is the code:
Private Sub Workbook_Open()
'Saves template with standard filename
Dim myPath As String, myFile As String, myExt As String
myPath = "Path"
myFile = "Constant " & Format(Date, "MMMM DD, YYYY")
myExt = ".xls"
If ActiveWorkbook.Name <> "Template.xls" Then _
ActiveWorkbook.VBProject.VBComponents.VBE.ActiveCodePane.CodeModule.DeleteLines 1, 11
If ActiveWorkbook.Name = "Template.xls" Then _
ActiveWorkbook.SaveAs Filename:=myPath & myFile & myExt
End Sub
Where it hangs up is where the workbook name <> "Template.xls". When I open
the new file and manually run the code (F5), it works. I get an "Object
Variable or With not defined" error. I tried adding a Call Workbook_Open line
before End Sub, and it still hung up. Is the active workbook still the
Template? How can I make sure that the active workbook is the newly saved one?