2016-08-09 180 views
1

我有以下宏來創造一個Excel文件的文件夾中的文件夾:保存PDF文件

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文件將被保存在第一個宏中創建的文件夾中。

你有什麼想法我可以做到這一點?

+0

網絡中有類似的問題。你可以試試這裏:http://stackoverflow.com/questions/27219784/vba-print-to-pdf-and-save-with-automatic-file-name?rq=1 –

回答

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 

即從

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

改變子Button_PDF_200Filename參數

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

.. 喜之道,

你也可以嘗試這樣的事情:

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 

玩得開心!