Suggested save as code with ommission warning

stuo81

New Member
Joined
Mar 10, 2013
Messages
13
Hi I am trying to alter a sugested save as code which currently looks like this:Sub buttonSave_Click()'Prompt to save fileOn Error GoTo Error_Handler' Keyboard Shortcut: Ctrl+Shift+GDim strFilePath As String'Prompt for a WO if none inputstrWO = Sheet1.txtWO.TextIf IsNull(strWO) Or strWO = "" Then MsgBox ("Please enter a work order number so you can save the jobsheet.") Sheet1.txtWO.SetFocusElse strFileNameSuggestion = "JS-" & Sheet1.txtWO.Text & "-" & Sheet1.txtAddress.Text 'expression.GetSaveAsFilename(InitialFilename, FileFilter, FilterIndex, Title, ButtonText) strFile = Application.GetSaveAsFilename _ (strFileNameSuggestion, Title:="File Save as", _ FileFilter:="Excel Files *.xls (*.xls),") If strFile = False Then MsgBox "File NOT saved", vbExclamation Else ActiveWorkbook.SaveAs Filename:=strFile End IfEnd IfGoTo Error_EndError_Handler: Error_End:End SubThis was not written by me and gives a nice message box if the work order box is left blank prompting for it to be completed.What I would like to do is alter this to stop staff entering extended work orders - we have a long version and a short version Long e.g. = 120000654321Short (required) e.g 654321 (just the last 6 digits from the long work order are required)I would like a message box warning to pop up if anyone tries to save the sheet with the long work order (as opposed to the short) saying "Please enter a work order number leaving out 120000 so you can save the jobsheet.")Any help is much appreciated.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try:

Rich (BB code):
Sub buttonSave_Click()
'   Prompt to save file
    On Error GoTo Error_Handler
'   Keyboard Shortcut: Ctrl+Shift+G
    Dim strFilePath As String
'   Prompt for a WO if none input
    strWO = Sheet1.txtWO.Text
    If IsNull(strWO) Or strWO = "" Then
        MsgBox ("Please enter a work order number so you can save the jobsheet.")
        Sheet1.txtWO.SetFocus
    ElseIf Len(strWO) > 6 Then
        MsgBox "Please enter a work order number leaving out 120000 so you can save the jobsheet."
        Sheet1.txtWO.SetFocus
    Else
        strFileNameSuggestion = "JS-" & Sheet1.txtWO.Text & "-" & Sheet1.txtAddress.Text
'       expression.GetSaveAsFilename(InitialFilename, FileFilter, FilterIndex, Title, ButtonText)
        strFile = Application.GetSaveAsFilename _
        (strFileNameSuggestion, Title:="File Save as", _
        FileFilter:="Excel Files *.xls (*.xls),")
        If strFile = False Then
            MsgBox "File NOT saved", vbExclamation
        Else
            ActiveWorkbook.SaveAs Filename:=strFile
        End If
    End If
    GoTo Error_End
Error_Handler:
Error_End:
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top