Vba 将Excel工作表导出为PDF时出现400和1004错误
请参阅下面的代码:Vba 将Excel工作表导出为PDF时出现400和1004错误,vba,excel,pdf,Vba,Excel,Pdf,请参阅下面的代码: Sub SmartPDF_Generator() Dim answer As Integer pdfName = ActiveSheet.Cells(1, 5) & " __ " & Cells(1, 8) answer = MsgBox("Please confirm creat dashboard for Carrier" & Cells(1, 5) & " Event" & Cells(
Sub SmartPDF_Generator()
Dim answer As Integer
pdfName = ActiveSheet.Cells(1, 5) & " __ " & Cells(1, 8)
answer = MsgBox("Please confirm creat dashboard for Carrier" & Cells(1, 5) & " Event" & Cells(1, 8), vbYesNo + vbQuestion, "Comfirm dashboard")
If answer = vbNo Then
MsgBox ("Please select your carrier and event combination again")
Else
ChDir ("C:\test\")
fileSaveName = ActiveSheet.Cells(1, 5) & " __ " & Cells(1, 8)
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
fileSaveName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
MsgBox "File Saved " & " " & fileSaveName
End If
Application.StatusBar = False
End Sub
您需要检查
ActiveSheet.Cells(1,5)
和Cells(1,8)
是否为空,然后才能继续执行代码。为什么在第二种情况下不使用ActiveSheet
?如果没有该限定符,您只会自找麻烦。您的代码在填充了E1和H1的工作表上对我有效,但如果它们都为空,我会得到错误1004…您应该使用定义良好的工作表对象,而不是依赖Excel猜测您正在处理的工作表。坏习惯