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