+ Reply to Thread
Results 1 to 6 of 6

VALIDATE WB NAME

  1. #1
    AD108
    Guest

    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. #2
    Forum Contributor
    Join Date
    03-24-2004
    Location
    Edam Netherlands
    Posts
    181
    If Not Instr(UCase(filename), "AIR CONTAINER") Then

  3. #3
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >
    > 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. #4
    AD108
    Guest

    Re: 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" <[email protected]> wrote in message
    news:O#[email protected]...
    > 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" <[email protected]> wrote in

    message
    > news:[email protected]...
    > >
    > > 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. #5
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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" <[email protected]> wrote in message
    > news:O#[email protected]...
    > > 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" <[email protected]> wrote in

    > message
    > > news:[email protected]...
    > > >
    > > > 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. #6
    AD108
    Guest

    Re: VALIDATE WB NAME

    Thank you very much,

    AD108

    "Bob Phillips" <[email protected]> wrote in message
    news:#[email protected]...
    > 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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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" <[email protected]> wrote in message
    > > news:O#[email protected]...
    > > > 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" <[email protected]> wrote in

    > > message
    > > > news:[email protected]...
    > > > >
    > > > > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1