Hello,
I have used the following code for quite a while and it has worked fine. Now I made a tweak to the code below to save a worksheet file as a PDF instead of an XLSX file and for some reason it will no longer run completely. It is stopping right after it has saved the pdf file. I do not get any error messages, all the excel pages go blank with grayed out toolbars.
The interesting thing is that the file does show up in the folder, but I cannot open it because it is corrupted. So it sounds like it is not actually saving the file correctly or completely? I disabled the display alerts box thinking maybe it was a popup but that did not change anything. I can't step into anything after this point because of the windows going blank.
Does anyone see anything amiss in the code? I appreciate any input at all - thank you
I have used the following code for quite a while and it has worked fine. Now I made a tweak to the code below to save a worksheet file as a PDF instead of an XLSX file and for some reason it will no longer run completely. It is stopping right after it has saved the pdf file. I do not get any error messages, all the excel pages go blank with grayed out toolbars.
The interesting thing is that the file does show up in the folder, but I cannot open it because it is corrupted. So it sounds like it is not actually saving the file correctly or completely? I disabled the display alerts box thinking maybe it was a popup but that did not change anything. I can't step into anything after this point because of the windows going blank.
Does anyone see anything amiss in the code? I appreciate any input at all - thank you
VBA Code:
Sub SendFallProtectionReport()
Dim wb As Workbook
Dim myName As Variant
' This subset creates the log entry for the completed inspection and then sends out the email.
myName = InputBox("NOTICE" & vbCrLf & "By entering your name you are affirming that you have reviewed the report and that" _
& " you agree with all of the findings as noted." & vbCrLf & vbCrLf & "Enter Name: ", "Inspection Report Submittal")
If myName = "" Then
Exit Sub
Else
End If
Range("'Fall Protection Report'!J2").Value = myName
Range("'Fall Protection Report'!K2").Value = Now()
myTime = Range("'Fall Protection Report'!J3").Value
Worksheets("Inspection Log").Activate
Application.EnableEvents = False
Sheets("Fall Protection Report").Shapes("Group 16").Visible = False
Sheets("Fall Protection Report").ExportAsFixedFormat _
Type:=xlTypePDF
Set wb = ActiveWorkbook
With wb
Application.DisplayAlerts = False
.SaveAs _
"\\MESSDV002.na.infineon.com\Facilities\DeptData\EH&S\Compliance and EHS\Facilities Inspections\Fall Protection\Fall Protection Inspection Report " _
& Format(Now, "yy_mmdd") & ".pdf"
.Close True
'The code stops here, screens go blank....
Application.DisplayAlerts = True
End With
Sheets("Fall Protection Report").Shapes("Group 16").Visible = True
With Sheets("Inspection Log")
nextrow = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & nextrow) = "Fall Protection"
.Range("B" & nextrow) = myTime
.Range("C" & nextrow) = myName
.Range("D" & nextrow).Formula = "=Hyperlink(" & Chr(34) & "\\MESSDV002.na.infineon.com\Facilities\DeptData\EH&S\Compliance and EHS\Facilities Inspections\Fall Protection\Fall Protection Inspection Report " _
& Format(myTime, "yy_mmdd") & ".xlsx" & Chr(34) & ")"
End With
Worksheets("Fall Protection Report").Activate
ActiveSheet.Range("C1:H30").Select
Range("K1").Select
' Show the envelope on the ActiveWorkbook.
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Introduction = " The following facility inspection has been completed. "
.Item.To = Range("Coding!A22").Value
.Item.Subject = "Fall Protection Inspection Completed"
.Item.Send
End With
Application.DisplayAlerts = True
End Sub