VBA Code for saving as PDF on PC and MAC

terryjmatthews84

New Member
Joined
Apr 27, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi guys, I'm new to the forum and forums altogether so excuse any mistakes, I've read the rules so fingers crossed.

I have a macro which enables me to save the current worksheet as a PDF using a couple of cells for the file name and saving to my business drop box location however, this does not work on the MAC.

With employees using PC's and MAC's, I wondered if there was a code I can use which will work on both or, a code that will work on the MAC and I can just add another button in the sheet for MAC users. The code that works on the PC is as follows:

Sub PDFPO()
With ActiveSheet
.ExportAsFixedFormat 0, Environ("USERPROFILE") & "\Dropbox (TJM)\TJM Team Folder\TM\TJM Filing Structure\6. Financial Management\1. TJM\4. Financial Workbook\Purchase Orders OUT\" & _
.Range("L13").Value & "_" & .Range("W2").Value & "_" & Format(Date, "dd-mm-yyyy") & ".pdf", OpenAfterPublish:=True
End With
End Sub

The above code saves the worksheet as PDF under the file name given in cells L13 and W2 with spaces and todays date. It then saves the file in the location "Purchase Orders OUT".

Any help would be greatly appreciated.

Thank you
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Give a try to the following sub. It has been tested to work on both Win Excel 2010 and Mac Excel 2011. Modify the "Desktop" and "Test" in the file path as needed.
Note: OpenAfterPublish:=True has no effect on Mac.
VBA Code:
Sub PDFPO()
    Dim FileName As String
    #If Mac Then
        FileName = MacScript("return (path to home folder) as string") & "Desktop:Test:"
    #Else
        FileName = Environ("USERPROFILE") & "\Desktop\Test\"
    #End If
    With ActiveSheet
        FileName = FileName & .Range("L13").Value & "_" & .Range("W2").Value & "_" & Format(Date, "dd-mm-yyyy") & ".pdf"
        .ExportAsFixedFormat 0, FileName, OpenAfterPublish:=True
    End With
End Sub
 
Upvote 0
All kinds of VBA stuff used to work in Excel 2011 on the Mac, including file operations like this.

Excel 2016+ on the Mac is a totally different beast. Apple makes software (i.e., Microsoft Office) run within a sandboxed area to prevent malware to run amok. Safe, but it makes it very difficult to work with the file system. I would suggest looking at Ron de Bruin's Mac Excel Tips.
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,786
Members
448,992
Latest member
prabhuk279

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