Help with Saving Spreadsheet as PDF using VBA

Tyrell

New Member
Joined
May 10, 2017
Messages
1
Hey y'all,

For a work project I am attempting to save a spreadsheet as a pdf in a specific folder but I now that I have figured out how to navigate to that folder (or create it if it doesn't already exist), I keep getting a fail to print error for an undefined object. Due to the nature of my work I cannot post the spreadsheet I am working from, but I can point out in which line the code stops working when I go "step" through it in excel.

I am using excel 2016 for Mac.

Much Thanks
Rich (BB code):
Sub SaveCheckRequestPDFIn2016FromAuditSummary()


    Dim FileName2 As String
    Dim FolderName2 As String
    Dim Folderstring2 As String
    Dim FilePathName2 As String


    ActiveWorkbook.Sheets("Audit Summary 10% Cap").PageSetup.Orientation = xlPortrait

    FileName2 = ActiveWorkbook.Sheets("Audit Summary 10% Cap").Range("N3") & "_2016_WCAudit" & ".pdf"


    Folderstring2 = CreateFolderinMacOffice2016(NameFolder:="/")
    FilePathName2 = Folderstring2 & Application.PathSeparator & FileName2


    ActiveWorkbook.Sheets("Sheet1").Range("A1:J75").ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
    FilePathName2, Quality:=xlQualityStandard, _ --> THIS IS WHERE THE CODE STOPS WORKING AND I GET THE FOLLOWING ERROR 

Run-time error '1004':Application-defined or object-defined error


    IncludeDocProperties:=True, IgnorePrintAreas:=False

    MsgBox "You can find the PDF file in this location : " & FilePathName2


End Sub






Function CreateFolderinMacOffice2016(NameFolder As String) As String


    Dim OfficeFolder As String
    Dim PathToFolder As String
    Dim TestStr As String
    Dim FolderName2 As String


    FolderName2 = ActiveWorkbook.Sheets("Audit Summary 10% Cap").Range("N3") & "_Workers Compensation"


    OfficeFolder = MacScript("return POSIX path of (path to desktop folder) as string")
    OfficeFolder = Replace(OfficeFolder, "/Desktop", "") & _
        "Library/Group Containers/UBF8T346G9.Office/WCAudits/" & FolderName2


    PathToFolder = OfficeFolder & NameFolder


    On Error Resume Next
    TestStr = Dir(PathToFolder, vbDirectory)
    On Error GoTo 0
    If TestStr = vbNullString Then
        MkDir PathToFolder
        MsgBox "You can find the new folder in this location :" & PathToFolder
    End If
    CreateFolderinMacOffice2016 = PathToFolder
End Function
 
Last edited by a moderator:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top