将PDF文件自动保存到新文件夹中
我有以下macros在Excel文件所在的文件夹中创build一个文件夹:
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
我有以下的macros来创build一个PDF文件:
Sub Button_PDF_200() ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ ThisWorkbook.Path & "\" & "test.pdf", Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True End Sub
现在我希望在第二个macros中创build的PDF文件将保存在第一个macros中创build的文件夹中。
你有什么想法我可以做到这一点?
也许就是这样?
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
这就是改变子Button_PDF_200
的Filename
参数
ThisWorkbook.Path & "\" & "test.pdf"
至
ThisWorkbook.Path & "\" & "Folder_01" & "\" & "test.pdf"
嗨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
玩的开心!