View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
AD108 AD108 is offline
external usenet poster
 
Posts: 72
Default VALIDATE WB NAME

Thank you very much,

AD108

"Bob Phillips" wrote in message
...
The BeforeSave event has the SaveAsUI argument which is rue for SaveAs,
False for Save.

I don't think you necessarily need it, as if this is a new workbook,

SaveAs
is the default, so you could just use

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim sFilename As String
On Error GoTo wb_exit
Application.EnableEvents = False
Cancel = True
sFilename = Application.GetSaveAsFilename
If Not UCase(sFilename) Like "*AIR CONTAINER*" Then
MsgBox "Save with correct name"
Else
ThisWorkbook.SaveAs filename:=sFilename
End If
wb_exit:
Application.EnableEvents = True
End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"AD108" wrote in message
...
Hi Bob,

How would I test for either save or saveas.

With the code I wrote, it made the msgbox come up as intented, but when

I
close the message box, the getfilename dialouge pops up again. It then
allows the user to save it as whatever name they put in.

Maybe it is not going to work in the "before save" event handler?

"Bob Phillips" wrote in message
...
Like should work okay.

To the OP, what do you mean by ambiguous results? I note you are not

testing
whether they have used the SaveAs or Save.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Kaak" wrote in

message
...

If Not Instr(UCase(filename), "AIR CONTAINER") Then


--
Kaak

------------------------------------------------------------------------
Kaak's Profile:
http://www.excelforum.com/member.php...fo&userid=7513
View this thread:

http://www.excelforum.com/showthread...hreadid=557189