ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete code after use (https://www.excelbanter.com/excel-programming/400128-delete-code-after-use.html)

[email protected]

Delete code after use
 
'kay, so i'm a dummy.
have a workbook Template that i've added the following code to:

Private Sub Workbook_Open()
ans = InputBox("Name the new workbook")
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings
\FredFarnswithers\Desktop\" & ans & ".xls"
End Sub

works fine, however once saved, then reopened, the input box apears,
etc.
How do i get rid of the code, once the template is saved as a newly
named workbook?

Any help GRATEFULLY received!!
Hugh


Tom Ogilvy

Delete code after use
 
It might be easiest to use an if statement in your code so it only runs when
the workbook name contains a certain string or you have your code create a
hidden defined name and have your code check for its existence.

If you really want to remove it, you can start by looking at this article:

http://support.microsoft.com/kb/172109
VBA: How To Delete a Sub Procedure After It Runs Once


--
Regards,
Tom Ogilvy

" wrote:

'kay, so i'm a dummy.
have a workbook Template that i've added the following code to:

Private Sub Workbook_Open()
ans = InputBox("Name the new workbook")
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings
\FredFarnswithers\Desktop\" & ans & ".xls"
End Sub

works fine, however once saved, then reopened, the input box apears,
etc.
How do i get rid of the code, once the template is saved as a newly
named workbook?

Any help GRATEFULLY received!!
Hugh



[email protected]

Delete code after use
 
Tom, thanks for the answer. Ended up with:

Private Sub Workbook_Open()

If ActiveWorkbook.Name = "JobCostBook.xlt" Then
ans = InputBox("Name the new workbook - or heads will roll!")
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings
\FredFarnswiggle\Desktop\" & ans & ".xls"

'MsgBox "The New Workbook has been Saved to your Desktop
Folder named 'Job Costs' "

If ActiveWorkbook.Name < "JobCostBook.xlt" Then MsgBox "Carry on,
Mates! Disregard those maggots on the 9th Floor"
End If
End Sub

works so far......
again, thank you!








On Oct 27, 9:38 am, Tom Ogilvy
wrote:
It might be easiest to use an if statement in your code so it only runs when
the workbook name contains a certain string or you have your code create a
hidden defined name and have your code check for its existence.

If you really want to remove it, you can start by looking at this article:

http://support.microsoft.com/kb/172109
VBA: How To Delete a Sub Procedure After It Runs Once

--
Regards,
Tom Ogilvy

" wrote:
'kay, so i'm a dummy.
have a workbook Template that i've added the following code to:


Private Sub Workbook_Open()
ans = InputBox("Name the new workbook")
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings
\FredFarnswithers\Desktop\" & ans & ".xls"
End Sub


works fine, however once saved, then reopened, the input box apears,
etc.
How do i get rid of the code, once the template is saved as a newly
named workbook?


Any help GRATEFULLY received!!
Hugh













On Oct 27, 9:38 am, Tom Ogilvy
wrote:
It might be easiest to use an if statement in your code so it only runs when
the workbook name contains a certain string or you have your code create a
hidden defined name and have your code check for its existence.

If you really want to remove it, you can start by looking at this article:

http://support.microsoft.com/kb/172109
VBA: How To Delete a Sub Procedure After It Runs Once

--
Regards,
Tom Ogilvy

" wrote:
'kay, so i'm a dummy.
have a workbook Template that i've added the following code to:


Private Sub Workbook_Open()
ans = InputBox("Name the new workbook")
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings
\FredFarnswithers\Desktop\" & ans & ".xls"
End Sub


works fine, however once saved, then reopened, the input box apears,
etc.
How do i get rid of the code, once the template is saved as a newly
named workbook?


Any help GRATEFULLY received!!
Hugh





All times are GMT +1. The time now is 12:21 PM.

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