所以我有一个宏,它工作得很好,如下所示。它遍历数据验证下拉列表,并在下拉列表中为每个国家/地区保存一个 pdf。但是,当我尝试编辑宏以使文件名包括国家名称 (D14) 之外的日期时,我遇到运行时错误 1004 无法保存文档。我对 VBA 很陌生,所以我不知道如何解决这个问题......我真的很感激一些帮助
斯蒂芬
Sub Create_PDFs()
'
' Create_PDFS Macro
'
' Keyboard Shortcut: Ctrl+y
'
Const sheetToExportName = "Graphs"
Const sheetWithCountryList = "Master Sheet"
Const CountryListAddress = "AQ6:AQ38"
Const chosenCountryCell = "D14"
Const sheetWithChosenCell = "Graphs"
Dim CountryList As Range
Dim anyCountry As Range
Set CountryList = _
ThisWorkbook.Worksheets(sheetWithCountryList). _
Range(CountryListAddress)
For Each anyCountry In CountryList
ThisWorkbook.Worksheets(sheetWithChosenCell). _
Range(chosenCountryCell) = anyCountry
ThisWorkbook.Worksheets(sheetToExportName).ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"N:\International Finance Division\RAT Advanced Economies - Chartpacks\Country Risks\Created PDFs\" & ActiveSheet.Range("D14").Value & " - Country Risk Indicators.pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=False, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Next
Set CountryList = Nothing
End Sub