Mac Export to .PDF

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
Office Version
  1. 365
Platform
  1. Windows
I am having issues with the following code when trying to export a worksheet range to a PDF output
VBA Code:
Option Explicit

Sub CreateInvoices()

Dim wbInvoice As Workbook
Dim wsInvoice As Worksheet

Dim rngRow As Range

Dim strPath As String
Dim strFileName As String

Set rngRow = Sheets("Service Invoice").Range("SI_Start").Offset(1, 0)

Application.ScreenUpdating = False

Set wsInvoice = Sheets("Invoice")

strPath = ActiveWorkbook.Path & "/Invoices/"

Sheets("Invoice").Unprotect

Do Until rngRow.Offset(0, -17) = ""
   If rngRow <> "" Then
      If UCase(rngRow.Offset(0, 8)) = "Y" Then
         Else
         Range("Invoice_Offset") = rngRow.Row - Range("SI_Start").Row
         
         strFileName = Range("Invoice_FileName")
         strFileName = ReplaceIllegalChar(strFileName)

         wsInvoice.Copy

        Set wbInvoice = ActiveWorkbook

        wbInvoice.SaveAs _
           Filename:=strPath & strFileName & ".pdf", _
           FileFormat:=xlPDF, _
           PublishOption:=xlSheet

        ActiveSheet.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=strPath & strFileName & ".pdf", _
            Quality:=xlQualityMinimum, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, _
            OpenAfterPublish:=False

         Range("Invoice_Flatten").Select

         Selection.Copy

         Selection.PasteSpecial xlValues

         Range("Invoice_Offset") = ""
         Range("Invoice_FileName") = ""

         Range("A1").Select

         wbInvoice.SaveAs _
            Filename:=strPath & strFileName & ".xlsm", _
            FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
           CreateBackup:=False

         wbInvoice.Close savechanges:=False

         Set wbInvoice = Nothing

         rngRow.Offset(0, 8) = "Y"
      End If
      Else
   End If

   Set rngRow = rngRow.Offset(1, 0)
Loop

Range("Invoice_Offset") = ""

Sheets("Invoice").Protect

Set rngRow = Nothing

Set wsInvoice = Nothing

Sheets("Service Invoice").Select

Application.ScreenUpdating = True

MsgBox ("All invoices have been created"), vbInformation, "Invoices Created"

End Sub
The issue is when either of the line to either SaveAs or Export as a PDF. I only need one in the code but have both in there to demonstrate what I have tried to use.

TIA
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
And what exactly happens? You may just be running into Apple sandboxing.
 
Upvote 0
It's returning a method or workbook failed.

I have tried the sandboxing solution but it seems it's the actual exporting as the code to save a flat file Excel file works based on the same path.
 
Upvote 0
Which version of Mac Excel? Also, what is the actual value of strPath & strFileName & ".pdf" when it fails?

Edit: just noticed - PublishOption is not a valid parameter for SaveAs.
 
Last edited:
Upvote 0
strPath is returning the folder path that the file is saved in and strFileName is pulling a value from a cell (doesn't have an error in the cell)

Version is 15.25 (160817)
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,432
Members
448,961
Latest member
nzskater

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