我正在尝试使用以下代码将特定工作表另存为PDF,但错误信息显示为Run Time Error'1004': Method 'SaveAs' of object '_Worksheet' Failed
Sub SaveAsPDF()
Dim path As String
Dim MyDate As String
Dim WS As Worksheet
path = "c:\invoice\"
MyDate = Date
MyDate = Format(MyDate, "dd_mm_yyyy")
Application.DisplayAlerts = False
For Each WS In ThisWorkbook.Worksheets
WS.SaveAs Filename:=path & Range("D6").Text & "-" & Range("K6").Value & "-" & _
MyDate, FileFormat:=xlTypePDF
Next
Application.DisplayAlerts = True
ActiveWorkbook.Close savechanges:=False
End Sub
答案 0 :(得分:0)
您需要使用HORIZONTAL = false
,而不是ExportAsFixedFormat
(以及相应的参数名称)
SaveAs