Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Change file name when saved to C drive

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default Change file name when saved to C drive

On Oct 2, 12:41*pm, Michael Lanier 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Change file name when saved to C drive

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
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
Excel file gets corrupt if saved in one particular drive Sweety Excel Discussion (Misc queries) 3 July 13th 09 04:59 PM
Hyperlinks change when file is saved Grey Geek Excel Worksheet Functions 7 June 10th 08 05:05 PM
Links to mapped drive change to refer to local hard drive SueD Links and Linking in Excel 1 May 8th 08 11:42 AM
Combobox Change Event when file is saved as E.Anderegg Excel Programming 1 October 1st 03 05:03 PM
Find links with code; change from G drive to C drive Sandy[_3_] Excel Programming 4 July 26th 03 07:24 PM


All times are GMT +1. The time now is 03:51 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"