将PDF文件自动保存在新文件夹中

时间:2016-08-09 09:32:25

标签: excel excel-vba vba

我有以下宏来在Excel文件所在的文件夹中创建一个文件夹:

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

我有以下宏来创建PDF文件:

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

现在我希望在第二个宏中创建的PDF文件将保存在第一个宏中创建的文件夹中。

你知道我怎么能这样做吗?

2 个答案:

答案 0 :(得分:0)

也许就是这样?

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

这正在改变子Filename中的Button_PDF_200参数

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

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

答案 1 :(得分:0)

.. 嗨Michi,

你也可以尝试这样的事情:

    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

玩得开心!

相关问题