i get a 400 error with this VBA code. Basically I want a control that they have to complete a field before they can print or close the form. If everything is complete and they hit the "send" button (macro) then it should either deny them from doing so or allow it to print as a pdf. It works fine as laid out if everything is filled in - it's when it's missing something, it gives the error and then ends on the VB screen. That would confuse them terribly.
Help!
Sub Make_PDF()
' Create and save .pdf
pdfName = Range("A9").Text
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
pdfName + " " + Format$(Date, "mm-dd-yyyy") + ".pdf" _
, Quality:=xlQualityMedium, IncludeDocProperties:=False, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If WorksheetFunction.CountBlank(Worksheets("sheet1").Range("A9:A11")) >= 1 Or WorksheetFunction.CountBlank(Worksheets("sheet1").Range("F9:F15")) >= 1 Then
MsgBox "Print disabled because at least one cell is left blank in Range A9:A11 or Range F9:F15"
Cancel = True
End If
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If WorksheetFunction.CountBlank(Worksheets("sheet1").Range("A9:A11")) >= 1 Or WorksheetFunction.CountBlank(Worksheets("sheet1").Range("F9:F15")) >= 1 Then
MsgBox "Close disabled because at least one cell is left blank in Range A9:A11 or Range F9:F15"
Cancel = True
End If
End Sub
Help!
Sub Make_PDF()
' Create and save .pdf
pdfName = Range("A9").Text
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
pdfName + " " + Format$(Date, "mm-dd-yyyy") + ".pdf" _
, Quality:=xlQualityMedium, IncludeDocProperties:=False, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If WorksheetFunction.CountBlank(Worksheets("sheet1").Range("A9:A11")) >= 1 Or WorksheetFunction.CountBlank(Worksheets("sheet1").Range("F9:F15")) >= 1 Then
MsgBox "Print disabled because at least one cell is left blank in Range A9:A11 or Range F9:F15"
Cancel = True
End If
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If WorksheetFunction.CountBlank(Worksheets("sheet1").Range("A9:A11")) >= 1 Or WorksheetFunction.CountBlank(Worksheets("sheet1").Range("F9:F15")) >= 1 Then
MsgBox "Close disabled because at least one cell is left blank in Range A9:A11 or Range F9:F15"
Cancel = True
End If
End Sub