I need some coding help. The code takes the Excel file and saves as a PDF file with a slightly different file name. The PDF file is supposed to go into a folder called "SavedWork" on the desktop.
Right now, if my desktop has the "SavedWork" folder, the code works (file is put in that folder). But if there isn't the "SavedWork" folder on the desktop, it doesn't (file won't save anywhere / code has error).
How do I change my code to:
* create the "SavedWork" folder on the desktop if it isn't already there on the desktop
Right now, if my desktop has the "SavedWork" folder, the code works (file is put in that folder). But if there isn't the "SavedWork" folder on the desktop, it doesn't (file won't save anywhere / code has error).
How do I change my code to:
* create the "SavedWork" folder on the desktop if it isn't already there on the desktop
VBA Code:
Dim sPath As String, sName As String
desktopDir = CreateObject("WScript.Shell").specialfolders("Desktop")
sPath = desktopDir & "\SavedWork"
sName = ThisWorkbook.Name
sName = Left(sName, InStrRev(sName, ".") - 1)
' Check to see if file exists
Dim strFileExists As String
Dim strFileName As String
Dim tsfile As String
strFileName = sName & "_" & "ISS" & ".pdf"
tsfile = sPath & "\" & strFileName
strFileExists = Dir(tsfile)
Dim AnswerYes As String
If strFileExists <> "" Then
MsgBox strFileName & " already exists", vbExclamation, "FileCheck"
AnswerYes = MsgBox("Overwrite File?", vbQuestion + vbYesNo, "FileCheck")
If AnswerYes = vbNo Then
GoTo Unhide
End If
End If
ThisWorkbook.Save
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, fileName:=sPath & "\" & sName & "_" & "ISS" & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True