I am trying to print an excel sheet to PDF but I keep getting errors. I am getting an error on the "ActiveSheet" line at the end.
I have tried various forms of this but they are all giving me an error.
Run -time error 1004 - Document not saved. The document may be open, or an error may have been encountered when saving
I have tried various forms of this but they are all giving me an error.
Run -time error 1004 - Document not saved. The document may be open, or an error may have been encountered when saving
Code:
Sub MakeReportsPDF()
Dim DEPT As String
Dim EENAME As String
Dim EMPLID As Variant
Dim FINAL As String
Dim GENERAL As String
Dim INITIAL As String
Dim JOB As String
Dim NEXTSTEP As String
Dim POINTS As Variant
Dim WRITTEN As String
Dim DOH As Date
Dim SaveName As String
Dim ADate As String
Dim ARDATE As String
Dim Title As String
Dim User As String
User = Environ$("UserName")
Sheets("POINT LIST").Select
Range("A1").Select
lrow = Cells(Rows.Count, 2).End(xlUp).Row
For x = 2 To 10
Sheets("POINT LIST").Select
DEPT = Range("F" & x) & "-" & Range("G" & x)
EENAME = Range("B" & x)
EMPLID = Range("A" & x)
FINAL = Range("N" & x)
GENERAL = Range("P" & x)
INITIAL = Range("L" & x)
JOB = Range("H" & x) & "-" & Range("I" & x)
NEXTSTEP = Range("O" & x)
POINTS = Range("K" & x)
WRITTEN = Range("M" & x)
DOH = Range("D" & x)
Sheets("Corrective Report").Activate
Range("EENAME") = EENAME
Range("EMPLID") = EMPLID
Range("JOB") = JOB
Range("HIRE") = DOH
Range("DEPT") = DEPT
Range("General") = GENERAL
Range("PTS") = POINTS
Range("INITIAL") = INITIAL
Range("WRITTEN") = WRITTEN
Range("FINAL") = FINAL
Range("NEXTSTEP") = NEXTSTEP
ARDATE = Range("ARDATE")
SaveName = EENAME & "_Corrective Action Report_" & ARDATE
Path = "C:\Users\" & User & "\CAReports\" & SaveName
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & ".pdf"
Next x
End Sub