2
所以我有一个宏,它的工作原理如下。它通过数据验证下拉菜单循环,并为每个国家的下拉菜单保存pdf。但是,当我尝试编辑宏以便文件名包含除国家/地区名称(D14)之外的日期时遇到运行时错误1004文档无法保存。我是很新的VBA所以我不知道如何解决这个...我真的很感激一些帮助运行时错误1004当试图用文件名保存文件时没有保存文件
斯蒂芬
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
D14的值是否包含带“/”字符的日期?如果是这样,文件名不能有特殊字符,例如:,/等。 – shahkalpesh 2012-08-19 15:39:15