sj_robertson
New Member
- Joined
- Mar 21, 2010
- Messages
- 7
I have a macro that runs from a key combo to save the active worksheet to PDF.
It seems that this macro runs correctly and performs the requested operation (export to PDF), however, it throws up a run-time error, which prevents the macro from completing.
VBA repeatedly tells me (highlights during Debug) the offending code starts at .ExportAsFixedFormat and ends after OpenAfterPublish:=False, yet I cannot find anything wrong with the coding, despite having corrected the coding and reverted to my original format numerous times. The only thing I can assume is that the underscore in the filename is causing the issue, yet all resources I have checked specify that underscore is a valid character...
What is even more confusing is that the macro does produce my final PDF (with the file name in the format CellRef_CellRef); it just fails to delete sheet 1 after doing so... If I then, after deleting Sheet1 manually, run the macro again, the macro seems to then run perfectly (overwriting the previously exported file) without throwing up any errors whatsoever.
Any help would be greatly appreciated, as I'm certain I've grown a few more grey hairs since this morning!
It seems that this macro runs correctly and performs the requested operation (export to PDF), however, it throws up a run-time error, which prevents the macro from completing.
Code:
Sub ...
...
...
..
With ActiveSheet
.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:="C:\...correct path triple-checked!...\" & Cells(11, 10).Value & "_" & Cells(15, 8).Value & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
OpenAfterPublish:=False
'
End With
'
Sheets("Sheet1").Delete
'
End Sub
VBA repeatedly tells me (highlights during Debug) the offending code starts at .ExportAsFixedFormat and ends after OpenAfterPublish:=False, yet I cannot find anything wrong with the coding, despite having corrected the coding and reverted to my original format numerous times. The only thing I can assume is that the underscore in the filename is causing the issue, yet all resources I have checked specify that underscore is a valid character...
What is even more confusing is that the macro does produce my final PDF (with the file name in the format CellRef_CellRef); it just fails to delete sheet 1 after doing so... If I then, after deleting Sheet1 manually, run the macro again, the macro seems to then run perfectly (overwriting the previously exported file) without throwing up any errors whatsoever.
Any help would be greatly appreciated, as I'm certain I've grown a few more grey hairs since this morning!