Home

ExportasfixedFormat office 2010

jimrawcliffe
Occasional Visitor

I have the following macro which produces the desired effect but then errors

 

Any help appreciated

 

'This code will save each worsheet as a separate PDF
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
MsgBox name

concat = path & fol & name
MsgBox concat
With ws.PageSetup
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = False
.PaperSize = xlPaperA3
End With
ws.ExportAsFixedFormat xlTypePDF, fileName:=concat, OpenAfterPublish:=True

Next ws

Application.ScreenUpdating = True

End Sub