shapeshiftingkiwi
New Member
- Joined
- Mar 31, 2021
- Messages
- 33
- Office Version
- 365
- Platform
- Windows
Hello,
The below code is working as intended except that I want the Save_As5 sub to only run if the "Save Production Form" button is clicked. Right now it is saving as soon as the macro is run and then the usual pop up with the save pathway is appearing afterwards.
The below code is working as intended except that I want the Save_As5 sub to only run if the "Save Production Form" button is clicked. Right now it is saving as soon as the macro is run and then the usual pop up with the save pathway is appearing afterwards.
VBA Code:
Public Sub Save_Only()
English_Toggle
Dim Exitflag1 As Boolean, Exitflag2 As Boolean, Exitflag3 As Boolean, Exitflag4 As Boolean, Exitflag5 As Boolean, Exitflag6 As Boolean, Exitflag7 As Boolean
Dim fileSaved As Boolean
fileSaved = False
Save_As5 Exitflag1, Exitflag2, Exitflag3, Exitflag4, Exitflag5, Exitflag6, Exitflag7, fileSaved
End Sub
Private Sub Save_As5(ByRef Exitflag1 As Boolean, ByRef Exitflag2 As Boolean, ByRef Exitflag3 As Boolean, ByRef Exitflag4 As Boolean, ByRef Exitflag5 As Boolean, ByRef Exitflag6 As Boolean, ByRef Exitflag7 As Boolean, ByRef fileSaved As Boolean)
Exitflag1 = False
Exitflag2 = False
Exitflag3 = False
Exitflag4 = False
Exitflag5 = False
Exitflag6 = False
Exitflag7 = False
fileSaved = False
Dim ErrorCells As String
ErrorCells = ""
For Each Cell In ActiveSheet.Range("F14:F37")
If Cell.EntireRow.Hidden = False And Cell.value = "" Then
Exitflag1 = True
ErrorCells = ErrorCells & Cell.Offset(0, -2).value & ", "
End If
Next Cell
For Each Cell In ActiveSheet.Range("G14:G16,G18:G21,G27:G37")
If Cell.EntireRow.Hidden = False And Cell.value = "" Then
Exitflag2 = True
ErrorCells = ErrorCells & Cell.Offset(0, -3).value & ", "
End If
Next Cell
For Each Cell In ActiveSheet.Range("D5")
If Cell.value = "" Then
Exitflag3 = True
End If
Next Cell
For Each Cell In ActiveSheet.Range("H5")
If Cell.value = "" Then
Exitflag4 = True
End If
Next Cell
For Each Cell In ActiveSheet.Range("J5")
If Cell.value = "" Then
Exitflag5 = True
End If
Next Cell
For Each Cell In ActiveSheet.Range("C55")
If Cell.value = "" Then
Exitflag6 = True
End If
Next Cell
For Each Cell In ActiveSheet.Range("D57")
If Cell.value = "" Then
Exitflag7 = True
End If
Next Cell
If Exitflag3 = True Then
MsgBox "Enter a date"
ElseIf Exitflag4 = True Then
MsgBox "Enter a shift"
ElseIf Exitflag5 = True Then
MsgBox "Enter a line"
ElseIf Exitflag6 = True Then
MsgBox "Verify un-used labels have been removed from floor"
ElseIf Exitflag7 = True Then
MsgBox "Enter mill operator name"
Else
If Exitflag1 = True And Exitflag2 = True Then
MsgBox "missing information for " & ErrorCells
ElseIf Exitflag1 = True Then
MsgBox "missing lot number for " & ErrorCells
ElseIf Exitflag2 = True Then
MsgBox "missing quantity for " & ErrorCells
Else
With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Save"
.ButtonName = "Save Production Form"
.Application.DisplayAlerts = False
ThisWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\" & Range("Save_As!T2").value, FileFormat:=52
If .Show Then
.Execute
fileSaved = True
End If
End With
End If
End If
End Sub