Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Change File Name Warning

Is there a way I can have a message box alert someone,
when the file is opened, if they have changed the name of
the file? Basically, I don't want folks changing the name
of the file and want to warn them to change it back.

SDC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Change File Name Warning

Sdc,

code should be placed in ThisWorkbook
InstrRev only works with Excel2000 or newer.
warnings and/or exits should be amended to suit your needs.


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)

Dim sName$, sPath$
If SaveAsUI Then
Cancel = True
sPath = Application.GetSaveAsFilename( _
FileFilter:="Excel Workbooks (*.xls), *.xls")
If sPath = "False" Then
Exit Sub 'User cancelled
ElseIf sPath = ThisWorkbook.FullName Then
ThisWorkbook.Save
Else
sName = Mid(sPath, InStrRev(sPath, "\") + 1)
sPath = Left(sPath, InStrRev(sPath, "\"))
If sName < ThisWorkbook.Name Then
If vbOK = MsgBox( _
"Warning: will be saved to indicated path, " & _
"but file cannot be renamed", vbOKCancel) Then
If sPath = ThisWorkbook.Path & "\" Then
ThisWorkbook.Save
Else
On Error Resume Next 'need for cancel overwrite
Application.EnableEvents = False 'avoid triggering self
ThisWorkbook.SaveAs sPath & ThisWorkbook.Name
Application.EnableEvents = True
End If
End If
End If
End If
End If
End Sub


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"scrabtree23" wrote:

Is there a way I can have a message box alert someone,
when the file is opened, if they have changed the name of
the file? Basically, I don't want folks changing the name
of the file and want to warn them to change it back.

SDC


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
conditional formatting text warning and color change tcek Excel Worksheet Functions 7 October 16th 08 05:51 PM
Saved *.csv file gives SYLK file type warning upon Excel 2003 open Tom Excel Discussion (Misc queries) 5 March 19th 08 03:15 PM
Audio warning when cells change Ruben Excel Discussion (Misc queries) 1 August 17th 07 08:30 PM
warning: cannot change part of an array. how do I by pass this? Gwyneth Excel Worksheet Functions 3 December 8th 05 11:17 AM
no warning file in use LisaK Excel Discussion (Misc queries) 1 November 29th 05 06:00 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"