我之前已经运行了数百次宏,而上周却没有任何问题。今天,当我运行宏时,它给了我1004错误。调试时,出现错误的代码行是saveas命令。不知道为什么,但是之前没有问题。代码未更改,对目录的访问和权限也未更改。如果绕过saveas行,则导出到PDF命令会出现相同的错误。我在路径和文件名中都没有禁止的字符。我唯一想知道的是Windows更新是否损坏了某些内容。这些是过去一周在我的PC上安装的3个更新:
KB4494441
KB4497932
KB4499405
有人有这个问题吗?
Dim tempName As String
Dim tempName2 As String
tempName = path & "\" & directoryName & " " & Left(dateStamp, 9) & ".pdf"
tempName2 = path & "\" & directoryName & " " & Left(dateStamp, 9) & ".xlsx"
ActiveWorkbook.SaveAs fileName:=tempName2, _
FileFormat:=xlOpenXMLWorkbook, _
CreateBackup:=False
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
fileName:=tempName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False