LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Removing Macro in ThisWorkbook

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.ActiveCo dePane.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?
--
I am running on Excel 2003, unless otherwise stated.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Personal.xls macro that writes to ThisWorkBook Derek Bliss Excel Programming 3 July 18th 08 05:26 PM
Macro to add code to ThisWorkbook module excelnut1954 Excel Programming 2 June 2nd 08 08:45 PM
'ThisWorkbook' Macro Question Dan R. Excel Programming 9 January 19th 07 06:16 PM
Module1 vs Thisworkbook for Macro Craigm[_16_] Excel Programming 4 June 28th 05 01:17 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"