Roger Hanson
New Member
I am trying to create/find a VBA script to have a single button that will save the file as a pdf with cell B3 and B4 values and a date code as the file name and then print the second tab of the worksheet but I am having problems. The file prints out to a network printer without issue but when I try to open the saved pdf, it gives me an error stating that the file is not a supported file type or the file has been damaged. I suspect that the file is not really saving as a pdf. Can someone help me troubleshoot this code? I did not create the code, but found it online (probably in this forum somewhere). I am a Mechanical Engineer and coding is not among my strong skills.
Code:
Sub CommandButton21_Click()
resp = MsgBox("Complete Test?", vbYesNo)
If resp = vbYes Then
Dim sFile As String
Dim uname
sFile = "" & Format(Now(), "mm.dd.yy") & ".pdf"
uname = Range("B3") & Range("B4").Value
ActiveWorkbook.Save
ActiveWorkbook.SaveAs Filename:="C:\Users\roghanson\My Documents\Inspection Programs\Testing\" & uname & " " & sFile
End If
Sheets("Summary").PrintOut
End Sub