我有一些代码可以在特定位置保存特定的Excel工作表。我想更改代码以便保存在最初打开文件的同一目录中。目前它已设置为保存在我的C:\中,但是如果我从另一个文件中打开了文件直接,我希望它保存在那里。
Sheets("Lease Charts").Activate
With Sheets("Lease Charts")
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:\Temp " & Format(Range("L1"), "mm-dd-yyyy"), _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
答案 0 :(得分:1)
只有你ThisWorkbook.Path
喜欢这样:
With Sheets("Lease Charts")
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\Temp " & Format(Range("L1"), "mm-dd-yyyy"), _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
答案 1 :(得分:0)
通过从文件名中删除特定目录来计算它!
Sheets("Lease Charts").Activate
With Sheets("Lease Charts")
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="Temp " & Format(Range("L1"), "mm-dd-yyyy"), _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With