PC Review


Reply
Thread Tools Rate Thread

Change file name when saved to C drive

 
 
Michael Lanier
Guest
Posts: n/a
 
      2nd Oct 2010
I want to change the name of my file "Estimation File" to "Master
File" when I save it to (or if it's already in) my C drive. Sheet1!A1
has a formula that returns either 0 or 1. Following are the
conditions:

If Sheet1!A1 = 0 and file is in C drive, then no change to file name
If Sheet1!A1 = 1 and file is in C drive, then change file name to
"Master File"
Chane occurs only when the file is saved in/to C drive

Thanks for any solution you might have.

Michael
 
Reply With Quote
 
 
 
 
Don Guillett Excel MVP
Guest
Posts: n/a
 
      2nd Oct 2010
On Oct 2, 12:41*pm, Michael Lanier <michaelrlan...@gmail.com> wrote:
> I want to change the name of my file "Estimation File" to "Master
> File" when I save it to (or if it's already in) my C drive. *Sheet1!A1
> has a formula that returns either 0 or 1. *Following are the
> conditions:
>
> If Sheet1!A1 = 0 and file is in C drive, then no change to file name
> If Sheet1!A1 = 1 and file is in C drive, then change file name to
> "Master File"
> Chane occurs only when the file is saved in/to C drive
>
> Thanks for any solution you might have.
>
> Michael


Try this. I left in the "ask if overwrite" on purpose

Sub savefile()
If Sheets("Sheet1").Range("a1") = 1 Then
fn = "Master File.xls"
Else
fn = ThisWorkbook.Name
End If

ActiveWorkbook.SaveAs Filename:=fn, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
 
Reply With Quote
 
Michael Lanier
Guest
Posts: n/a
 
      3rd Oct 2010
Don,

Thanks for your help. I modified your suggestion as follows:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
If Sheets("Sheet1").Range("a1") = 1 Then
fn = "Master File.xls"
Else
fn = ThisWorkbook.Name
End If
ActiveWorkbook.SaveAs Filename:=fn, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub

I placed it in ThisWorkbook. It changes the file name as expected,
but then I get a popup that states "Excel has stopped working . . ."
I'm still a novice so the problem is probably obvious to you. Also,
I'm using 2003 if that makes a difference but I also run it as a
compatible in my 2007 on occasion. Thanks in advance if you have any
further suggestions.

Michael
 
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
Re: FAT 32 file saved on NTFS drive Ken Blake, MVP Windows XP General 1 31st May 2010 10:35 PM
Re: FAT 32 file saved on NTFS drive Barry Schwarz Windows XP General 0 29th May 2010 05:26 AM
fonts change from saved file jimp Microsoft Powerpoint 0 13th May 2010 05:30 PM
Hyperlinks change when file is saved Grey Geek Microsoft Excel Worksheet Functions 7 10th Jun 2008 05:05 PM
same title for every saved file. how do i change this?? =?Utf-8?B?bmF0dG9kYWlzdWtp?= Microsoft Word Document Management 1 16th Feb 2005 03:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:28 PM.