Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Check File Name before Save Event


So John I am having trouble with this. When I first tried it I coul
not get it to work. Then it started working. I then created a ne
file with a new name and tried it. Problems getting the routine to ru
during save.

Try creating a new file called Test.xls. Insert the name into the cod
below and adust your Right() formula.

I can't seem to get it to fire when I save the file. It just goe
ahead and saves it without it calling the routine. I can't figure ou
why it does not call the routine.

Thanks



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

Dim FileName As String

If ThisWorkbook.Name = "Test.xls" Then
Do
' returns path and name
FileName = Application.GetSaveAsFilename _
(Title:="Browse to a directory and enter a file name")

' check the name
If Right(FileName, 8) = "Test.xls" Then
' don't use Workbook1.xls
MsgBox "That file name is not permitted." & vbCrLf & _
"Please select another file name.", vbExclamation, _
"Invalid File Name"
ElseIf Len(Dir(FileName)) 0 Then
' duplicate name
MsgBox "A file with that name already exists." & vbCrLf & _
"Please select another file name.", vbExclamation, _
"File Exists"
ElseIf FileName = "False" Then
Exit Do
Else
Exit Do
End If
Loop

Cancel = True

If FileName < "False" Then
Application.EnableEvents = False
ThisWorkbook.SaveAs FileName
Application.EnableEvents = False
End If
End If
End Su

--
ExcelMonke
-----------------------------------------------------------------------
ExcelMonkey's Profile: http://www.excelforum.com/member.php...nfo&userid=522
View this thread: http://www.excelforum.com/showthread.php?threadid=26427

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
Check File Name before Save Event ExcelMonkey[_169_] Excel Programming 1 September 29th 04 01:46 AM
check folder event Mark[_17_] Excel Programming 6 June 18th 04 03:08 PM
Save File to Another Directory, but not change Users File Save location Mike Knight Excel Programming 1 May 28th 04 09:06 PM
Change Event.....Spell Check CLR Excel Programming 7 February 1st 04 05:05 PM
Help - Change Event triggered on File Save As Dee Veloper Excel Programming 4 October 29th 03 02:16 AM


All times are GMT +1. The time now is 01:42 AM.

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"