Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
validate | Excel Discussion (Misc queries) | |||
validate | Excel Discussion (Misc queries) | |||
Looking up a name and then being able to validate it | Excel Worksheet Functions | |||
Looking up a name and then being able to validate it | Excel Worksheet Functions | |||
How to validate | Excel Worksheet Functions |