I have no issues when I run the code below the first time - however if the .pdf file exists when I click on "No" it says there is an error and highlights the line of code that reads
"Sheets("Doc List").ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False"
Please help.
Sub PDf_Doc_List()
Dim strFolder As String
strFolder = ActiveWorkbook.Path & "\Bid Folder\"
'Determine whether folder exists
If Dir(strFolder, vbDirectory) = "" Then
' No it doesn't, so carry on...
If Dir(strFolder, vbNormal) <> "" Then Kill strFolder
' delete any normal file with that name.
' now create the folder
MkDir strFolder
End If
mypath = ActiveWorkbook.Path & "\Bid Folder\"
fn = "Doc List" & " - " & Format(Now(), "mm-dd-yy") & ".PDF"
fname = mypath & fn
FileInQuestion = Dir(fname)
If FileInQuestion <> "" Then
If MsgBox("This PDF Exists, Do you wish to Overwrite? By selecting NO, an additional PDF with Time Stamp will be created in Folder. ", vbYesNo) = 7 Then
fn = "Doc List" & " - " & Format(Now(), "mm-dd-yy, hh:mm") & ".PDF"
fname = mypath & fn
ElseIf output = 6 Then
fn = "Doc List" & " - " & Format(Now(), "mm-dd-yy") & ".PDF"
fname = mypath & fn
Exit Sub
End If
End If
Sheets("Doc List").ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
MsgBox "Your file has been saved in the following folder -- " & fname
End Sub
Bookmarks