Mac Export to .PDF

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,480
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
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,079
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
And what exactly happens? You may just be running into Apple sandboxing.
 

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,480
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.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,079
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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:

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,480
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)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,719
Messages
5,597,741
Members
414,171
Latest member
12Rev79

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
Top