Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 04-07-2022, 02:56 AM
kiwimtnbkr kiwimtnbkr is offline Exit Module sub code when cancel is selected Windows 10 Exit Module sub code when cancel is selected Office 2019
Advanced Beginner
Exit Module sub code when cancel is selected
 
Join Date: Oct 2017
Posts: 69
kiwimtnbkr is on a distinguished road
Default

This is the Workbook_BeforeSave code I am using:

Code:
Public Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, cancel As Boolean)
Dim ws As Worksheet
Set ws = ActiveSheet
Dim xFileName As String
Dim U7part As String, U8part As String, K13part As String
    If (Range("U7") = Empty) Then
        MsgBox "'Request number' is mandatory.", vbCritical, "text"
        cancel = True
        Range("U7").Select
    End
        Else
    If (Range("U8") = Empty) Then
        MsgBox "'Request date' is mandatory.", vbCritical, "text"
        cancel = True
        Range("U8").Select
    End
        Else
    If (Range("K13") = Empty) Then
        MsgBox "'Requesting Dept' is mandatory.", vbCritical, "text"
        cancel = True
        Range("K13").Select
    End
        Else
    If (Range("L33") = "click here to select") Then
        MsgBox "para. 3.b. 'Method of Delivery' is mandatory.", vbExclamation, "text"
        cancel = True
        Range("L33").Select
    End
        Else
    If (Range("L37") = Empty) Then
        MsgBox "para. 3.d. 'Date required by' is missing.", vbExclamation, "text"
        cancel = True
        Range("K37").Select
    End
        Else
Call RenameTemplateSheet
        U7part = ws.Range("U7").value
        U7part = Replace(Replace(U7part, " / ", "/"), "/", "_")
        U8part = ws.Range("U8").value
        U8part = Replace(Replace(U8part, " / ", "/"), "/", "_")
        K13part = ws.Range("K13").value
        K13part = Replace(K13part, "/", "_")
Range("U9").Select
If SaveAsUI <> False Then
    cancel = True
        xFileName = Application.GetSaveAsFilename(K13part & " text " & Range("A1").value & U7part & " dated " & U8part, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm", , "Save As xlsm file")
            If xFileName <> "False" Then
            Application.EnableEvents = False
            ActiveWorkbook.SaveAs Filename:=xFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
            Application.EnableEvents = True
        End If
    End If
    End If
    End If
    End If
    End If
End If
End Sub
Thanks heaps to any light you can shed on this....
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Standard Module, Class Module and UserForm jpl Word VBA 0 03-14-2022 07:20 AM
Exit Module sub code when cancel is selected VBA code not in module of new document produced by mail merge MP1989 Mail Merge 3 09-10-2018 02:16 PM
Exit Module sub code when cancel is selected pause VBA code to view PDF file then continue or cancel trevorc Excel Programming 3 06-17-2018 09:46 AM
Exit Module sub code when cancel is selected Inserting code line in Word Module mihnea96 Excel Programming 2 08-15-2017 04:57 AM
Exit Module sub code when cancel is selected Stop macro if no file is selected in dialog box (when user presses cancel instead of selecting file) spencerw.smith Word VBA 2 08-12-2014 07:56 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft