VBA-代码执行并产生所需的效果,但随后在Exportasfixedformat行上产生错误


0

我有一个宏用于导出所有工作表以在指定的子文件夹中分隔pdf。当我执行它时,在正确的位置生成pdfs并且标题为apporproately但是然后出错 - 错误5无效的过程调用或参数 - 任何想法?

    Sub SaveWorkshetAsPDF()
Application.ScreenUpdating = False

Dim ws As Worksheet
Dim path As String
Dim fol As String
Dim name As String
Dim concat As String
Dim fdObj As Object


path = ActiveWorkbook.path
fol = "\PDFs\"
Set fdObj = CreateObject("Scripting.FileSystemObject")
If fdObj.FolderExists(path & fol) Then
MsgBox "Found it", vbInformation
Else
fdObj.createfolder (path & fol)
MsgBox "folder created", vbInformation
End If

For Each ws In Worksheets


    name = ws.name
    concat = path & fol & name

    With ws.PageSetup
        .Orientation = xlLandscape
        .FitToPagesWide = 1
        .FitToPagesTall = False
        .PaperSize = xlPaperA3
    End With
    ws.ExportAsFixedFormat xlTypePDF, fileName:=concat
Next ws

Application.ScreenUpdating = True

End Sub

Answers:


0

添加文件扩展名以及ActiveWorkBook

For Each ws In Worksheets


name = ws.name
concat = path & fol & name & ".pdf"

With ws.PageSetup
    .Orientation = xlLandscape
    .FitToPagesWide = 1
    .FitToPagesTall = False
    .PaperSize = xlPaperA3
End With
ActiveWorkbook.ExportAsFixedFormat xlTypePDF, Filename:=concat
Next ws
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.