PDA

View Full Version : Export / Save as PDF in specific folder.



Auxie
10-18-2017, 06:35 AM
Dim strFilename, strDirname, strPathname, strDefpath As StringOn Error Resume Next ' If directory exist goto next linestrDirname = Range("Y3").Value ' New directory name
strFilename = Range("Y3").Value 'New file namestrDefpath = "\\path"'Default path nameIf IsEmpty(strDirname) Then Exit SubIf IsEmpty(strFilename) Then Exit Sub
MkDir strDefpath & "\" & strDirnamestrPathname = strDefpath & "\" & strDirname & "\" & strFilename 'create total string
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("Y3").Value _ , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _ :=False, OpenAfterPublish:=True

Hey,

I am having trouble with the above code - its creating the folder and the pdf but it does not save it.. I'm probably missing something super simple but im failing to spot it.

Thanks in advance.

mdmackillop
10-18-2017, 08:28 AM
Sub Test()
Dim strFilename, strDirname, strPathname, strDefpath As String
On Error Resume Next ' If directory exist goto next line
strDirname = Range("Y3").Value ' New directory name
strFilename = Range("Y4").Value 'New file name
strDefpath = ActiveWorkbook.Path 'Default path name
If IsEmpty(strDirname) Then Exit Sub
If IsEmpty(strFilename) Then Exit Sub
MkDir strDefpath & "\" & strDirname
strPathname = strDefpath & "\" & strDirname & "\" & strFilename 'create total string
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPathname, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub