1

I have the following macro to create a folder within the folder where the Excel file is:

Sub Folder_Test()
    If Dir(ThisWorkbook.Path & "\" & "Folder_01", vbDirectory) = "Folder_01" Then
        MsgBox "Folder already exists!"
    Else
        MkDir Application.ThisWorkbook.Path & "\" & "Folder_01"
    End If
End Sub

And I have the following macro to create a PDF file:

Sub Button_PDF_200()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        ThisWorkbook.Path & "\" & "test.pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub

Now I want that the PDF file which is created in the second macro will be saved in the folder which is created in the first macro.

Do you have any idea how I can do this?

Community
  • 1
  • 1
Michi
  • 4,663
  • 6
  • 33
  • 83
  • There are tons of similar questions in the web. You can try here: http://stackoverflow.com/questions/27219784/vba-print-to-pdf-and-save-with-automatic-file-name?rq=1 – V. Wolf Aug 09 '16 at 09:41

2 Answers2

0

Maybe just that?

Sub Button_PDF_200()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        ThisWorkbook.Path & "\" & "Folder_01" & "\" & "test.pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub

That is changing the Filename argument within the sub Button_PDF_200 from

ThisWorkbook.Path & "\" & "test.pdf"

to

ThisWorkbook.Path & "\" & "Folder_01" & "\" & "test.pdf"
DAXaholic
  • 33,312
  • 6
  • 76
  • 74
0

.. Hi Michi,

also you can try something like this:

    pdfName = ActiveSheet.Range("T1")
    ChDir "C:\Temp\" 'This is where youo set a defult file path.
    fileSaveName = Application.GetSaveAsFilename(pdfName, _
    fileFilter:="PDF Files (*.pdf), *.pdf")
    If fileSaveName <> False Then
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
        fileSaveName _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True
    End If
    MsgBox "File Saved to" & " " & fileSaveName

Have fun!

V. Wolf
  • 123
  • 1
  • 8