PC Review


Reply
Thread Tools Rate Thread

Delete code after use

 
 
hughaskew2@yahoo.com
Guest
Posts: n/a
 
      27th Oct 2007
'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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      27th Oct 2007
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

"(E-Mail Removed)" 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
>
>

 
Reply With Quote
 
hughaskew2@yahoo.com
Guest
Posts: n/a
 
      27th Oct 2007
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 <TomOgi...@discussions.microsoft.com>
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
>
> "hughask...@yahoo.com" 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 <TomOgi...@discussions.microsoft.com>
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
>
> "hughask...@yahoo.com" 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
#delete after code based delete =?Utf-8?B?QnJ1Y2U=?= Microsoft Access Form Coding 2 8th Aug 2007 02:20 AM
Will deleting a Form delete attached code? AND How to see ALL code in dB ? Mel Microsoft Access 2 30th Apr 2007 08:25 PM
Delete data in a linked Excel sheet using Access code or seql delete Rocky Microsoft Access External Data 9 26th Jun 2005 12:42 AM
code to delete a user/ code to move users into and out of groups =?Utf-8?B?dHc=?= Microsoft Access Security 11 30th May 2005 06:59 AM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Microsoft Excel Programming 0 27th Jan 2004 07:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 PM.