Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default VALIDATE WB NAME

I attemped to use the following code to force users to save the workbook
with a certain name.
It is not working, and produces ambiguous results. Any ideas.

Thanks in advance.

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

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VALIDATE WB NAME


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

--
Kaa
-----------------------------------------------------------------------
Kaak's Profile: http://www.excelforum.com/member.php...nfo&userid=751
View this thread: http://www.excelforum.com/showthread.php?threadid=55718

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VALIDATE WB NAME

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default VALIDATE WB NAME

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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VALIDATE WB NAME

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









  #6   Report Post  
Posted to microsoft.public.excel.programming
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









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
validate wAYNE Excel Discussion (Misc queries) 1 March 1st 10 06:21 PM
validate kyoshirou Excel Discussion (Misc queries) 18 June 6th 07 01:08 AM
Looking up a name and then being able to validate it twynsys Excel Worksheet Functions 0 November 29th 06 02:48 PM
Looking up a name and then being able to validate it twynsys via OfficeKB.com Excel Worksheet Functions 0 November 21st 06 04:43 PM
How to validate edwardpestian Excel Worksheet Functions 4 June 9th 06 01:13 AM


All times are GMT +1. The time now is 10:09 PM.

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"