Excel 如何将工作表另存为pdf和文件夹

Excel 如何将工作表另存为pdf和文件夹,excel,pdf,vba,Excel,Pdf,Vba,我有一个代码在这里保存为pdf文件,同时,我想使一个文件夹命名的单元格值和保存在该文件夹中的文件 Sub Button1_Click() Sheet3.ExportAsFixedFormat _ Type:=xlTypePDF, _ Filename:=ActiveWorkbook.Path & "\" & Sheet1.Range("A2").Value & "-" & Sheet1.Range("B2").Value, _ OpenAfterPublish:=

我有一个代码在这里保存为pdf文件,同时,我想使一个文件夹命名的单元格值和保存在该文件夹中的文件

Sub Button1_Click()
Sheet3.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & Sheet1.Range("A2").Value & "-" & Sheet1.Range("B2").Value, _
OpenAfterPublish:=True


End Sub

要创建文件夹,您需要使用
MkDir

Dim folder As String

folder = ActiveWorkbook.Path & "\" & Sheet1.Range("A2").Value
MkDir folder 'this makes the folder

Sheet3.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=folder & "\" & Sheet1.Range("B2").Value 'saves the file in that folder

如果有可能创建同名的文件夹/文件,我会添加一些If/Then语句来检查文件夹/文件是否首先存在。

要创建文件夹,需要使用
MkDir

Dim folder As String

folder = ActiveWorkbook.Path & "\" & Sheet1.Range("A2").Value
MkDir folder 'this makes the folder

Sheet3.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=folder & "\" & Sheet1.Range("B2").Value 'saves the file in that folder

如果有可能创建一个同名的文件夹/文件,我会添加一些If/Then语句来检查文件夹/文件是否先存在。

太好了!问题是,哪个单元格包含新文件夹名?或者新文件夹的名称是什么样子的?目前您正在使用的是
ActiveWorkbook.Path
,但是您想使用什么呢?太好了!问题是,哪个单元格包含新文件夹名?或者新文件夹的名称是什么样子的?目前您正在使用的是
ActiveWorkbook.Path
,但您想使用什么?