PC Review


Reply
Thread Tools Rate Thread

Auto Disable Macros on new sheet

 
 
DDub207
Guest
Posts: n/a
 
      30th Jul 2007
Hello, I'm a beginner at using Excel macros, and after much cursing I was
finally able to get two macros to run on the same workbook. The one I'm
having trouble with takes the data from a particular cell and uses it to
rename the file before saving it. The problem is, both macros are still
active when opening that new file. This is for invoices. The initial file
is a blank invoice where I want the macros to run. The secondary file is
saved as the customer's name. I do not want the macros to run on the
secondary file. What can be done to auto-disable the macros on the new file?
(These are both auto-run macros.)

Thanks,
Duane

'invoice number advance
Private Sub Workbook_Open()
Range("m3").Value = Range("m3").Value + 0.1
End Sub

'auto filename change
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisFile = Range("D13").Value
ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub

 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      30th Jul 2007
You have to find some way for the macro to distinguish between a workbook
you want to save and one you don't. I don't know what that might be. You
might put a "x" in a way out cell like IV1 to mark an 'old' workbook:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Range("IV1").Value = "" then ''New
Range("IV1").Value = "x" ''Mark as Old
Me.SaveAs Filename:=Range("D13").Value
End if
End Sub


--
Jim
"DDub207" <u36243@uwe> wrote in message news:75f48f54b5e08@uwe...
| Hello, I'm a beginner at using Excel macros, and after much cursing I was
| finally able to get two macros to run on the same workbook. The one I'm
| having trouble with takes the data from a particular cell and uses it to
| rename the file before saving it. The problem is, both macros are still
| active when opening that new file. This is for invoices. The initial
file
| is a blank invoice where I want the macros to run. The secondary file is
| saved as the customer's name. I do not want the macros to run on the
| secondary file. What can be done to auto-disable the macros on the new
file?
| (These are both auto-run macros.)
|
| Thanks,
| Duane
|
| 'invoice number advance
| Private Sub Workbook_Open()
| Range("m3").Value = Range("m3").Value + 0.1
| End Sub
|
| 'auto filename change
| Private Sub Workbook_BeforeClose(Cancel As Boolean)
| ThisFile = Range("D13").Value
| ActiveWorkbook.SaveAs Filename:=ThisFile
| End Sub
|


 
Reply With Quote
 
=?Utf-8?B?UmljaCBK?=
Guest
Posts: n/a
 
      30th Jul 2007
if you are basically trying to copy the invoice to a new workbook without the
macros then copy the worksheet to a new workbook and save only the sheet.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
dim ThisFile, ShName as string

ShName = Activesheet.Name
Sheets(ShName).Select
Sheets(ShName).Copy
ThisFile = Range("D13").Value

ActiveWorkbook.SaveAs Filename:= _
ThisFile, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
' if you want to change the sheet name to the person's name also or create
a new name
Windows(ThisFile).Activate
ActiveSheet.Name = ThisFile
End Sub


I didn't try running this from a BeforeClose routine. You may need to create
a button on your original worksheet and run the routine from there.



"DDub207" wrote:

> Hello, I'm a beginner at using Excel macros, and after much cursing I was
> finally able to get two macros to run on the same workbook. The one I'm
> having trouble with takes the data from a particular cell and uses it to
> rename the file before saving it. The problem is, both macros are still
> active when opening that new file. This is for invoices. The initial file
> is a blank invoice where I want the macros to run. The secondary file is
> saved as the customer's name. I do not want the macros to run on the
> secondary file. What can be done to auto-disable the macros on the new file?
> (These are both auto-run macros.)
>
> Thanks,
> Duane
>
> 'invoice number advance
> Private Sub Workbook_Open()
> Range("m3").Value = Range("m3").Value + 0.1
> End Sub
>
> 'auto filename change
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> ThisFile = Range("D13").Value
> ActiveWorkbook.SaveAs Filename:=ThisFile
> End Sub
>
>

 
Reply With Quote
 
DDub207 via OfficeKB.com
Guest
Posts: n/a
 
      31st Jul 2007
Thanks for your help. It's basically working except for two things. It's
asking if I want to save changes to "new invoice". I would like the blank
invoice, "new invoice" to close automatically without saving changes,
otherwise it won't be blank anymore. Also, it's opening the "customer name
(D13)" file. I would like the new file to save but remain closed. Is there
a way to do this? Also, the last 3 lines of the macro created an error.

Thanks again.

Rich J wrote:
>if you are basically trying to copy the invoice to a new workbook without the
>macros then copy the worksheet to a new workbook and save only the sheet.
>
>Private Sub Workbook_BeforeClose(Cancel As Boolean)
>dim ThisFile, ShName as string
>
>ShName = Activesheet.Name
>Sheets(ShName).Select
> Sheets(ShName).Copy
> ThisFile = Range("D13").Value
>
> ActiveWorkbook.SaveAs Filename:= _
> ThisFile, FileFormat:=xlNormal, _
> Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
> CreateBackup:=False
> ' if you want to change the sheet name to the person's name also or create
>a new name
> Windows(ThisFile).Activate
> ActiveSheet.Name = ThisFile
>End Sub
>
>I didn't try running this from a BeforeClose routine. You may need to create
>a button on your original worksheet and run the routine from there.
>
>> Hello, I'm a beginner at using Excel macros, and after much cursing I was
>> finally able to get two macros to run on the same workbook. The one I'm

>[quoted text clipped - 19 lines]
>> ActiveWorkbook.SaveAs Filename:=ThisFile
>> End Sub


--
Message posted via http://www.officekb.com

 
Reply With Quote
 
=?Utf-8?B?UmljaCBK?=
Guest
Posts: n/a
 
      31st Jul 2007
Try this -

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ThisFile, ShName As String

ShName = ActiveSheet.Name
ThisFile = Range("D13").Value
Sheets(ShName).Select
Sheets(ShName).Copy
ActiveWorkbook.SaveAs Filename:= _
ThisFile, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close ' closes the new single sheet workbook

Application.DisplayAlerts = False ' inhibits the Save message
ActiveWindow.Close ' continues to close the blank invoice

End Sub


"DDub207 via OfficeKB.com" wrote:

> Thanks for your help. It's basically working except for two things. It's
> asking if I want to save changes to "new invoice". I would like the blank
> invoice, "new invoice" to close automatically without saving changes,
> otherwise it won't be blank anymore. Also, it's opening the "customer name
> (D13)" file. I would like the new file to save but remain closed. Is there
> a way to do this? Also, the last 3 lines of the macro created an error.
>
> Thanks again.
>


 
Reply With Quote
 
DDub207 via OfficeKB.com
Guest
Posts: n/a
 
      31st Jul 2007
Everything works great. Thanks.

Rich J wrote:
>Try this -
>
>Private Sub Workbook_BeforeClose(Cancel As Boolean)
>Dim ThisFile, ShName As String
>
> ShName = ActiveSheet.Name
> ThisFile = Range("D13").Value
> Sheets(ShName).Select
> Sheets(ShName).Copy
> ActiveWorkbook.SaveAs Filename:= _
> ThisFile, FileFormat:=xlNormal, _
> Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
> CreateBackup:=False
> ActiveWorkbook.Close ' closes the new single sheet workbook
>
> Application.DisplayAlerts = False ' inhibits the Save message
> ActiveWindow.Close ' continues to close the blank invoice
>
>End Sub
>
>> Thanks for your help. It's basically working except for two things. It's
>> asking if I want to save changes to "new invoice". I would like the blank

>[quoted text clipped - 4 lines]
>>
>> Thanks again.


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200707/1

 
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
Word & Enable Macros and Disable macros Theresa Microsoft Word Document Management 1 29th Sep 2008 10:38 PM
Removing Excel message to enable macros or disable macros =?Utf-8?B?Ym1pbGxlcjI2Mw==?= Microsoft Excel Misc 2 13th Oct 2004 02:39 PM
Doc has no macros, but I'm prompted to enable/disable macros Microsoft Word Document Management 2 7th Oct 2004 09:34 AM
Suppress the Disable Macros / Enable Macros Dialog Shoji Karai Microsoft Excel Programming 5 24th Sep 2003 03:10 AM
Finding macros, Auto Correct and Auto Text entries George M. Lutz Microsoft Word New Users 1 20th Sep 2003 10:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:55 PM.