Consulting

Results 1 to 2 of 2

Thread: Export / Save as PDF in specific folder.

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    19
    Location

    Export / Save as PDF in specific folder.

    PHP Code:
    Dim strFilenamestrDirnamestrPathnamestrDefpath 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(strDirnameThen Exit SubIf IsEmpty(strFilenameThen 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.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •