VBA Save entire sheet to pdf. Prompt for location

ScousePete

New Member
Joined
Feb 10, 2008
Messages
33
Office Version
  1. 365
Platform
  1. MacOS
I'd like to have the entire sheet saved to pdf, with a prompt for the user to select the location.

I have found similar scripts that save the sheet, but not one that prompts for location

Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Do you just want a prompt for the location or the file name as well?
 
Upvote 0
file name can be preset (or the workbookname), just the file location should prompt
 
Upvote 0
Ok how about
VBA Code:
Sub ScousePete()
   Dim Fldr As String
   
   With Application.FileDialog(4)
      .AllowMultiSelect = False
      If .Show Then Fldr = .SelectedItems(1)
   End With
   With ActiveSheet
      .ExportAsFixedFormat xlTypePDF, Fldr & "\" & .Name, , , 1, , , 0
   End With
End Sub
This will save the active sheet as a pdf
 
Upvote 0
The sheet is locked, if that is relevant
 

Attachments

  • Screenshot 2021-12-01 at 11.39.52.png
    Screenshot 2021-12-01 at 11.39.52.png
    104.7 KB · Views: 16
Upvote 0
You will not get that error with the code I provided. Did you copy/paste the code or type it out?

Also what version of Excel & what platform are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Thanks. Is there a way to incorporate that code into your code?
 
Upvote 0
You can try
VBA Code:
Sub Select_Folder_On_Mac()
    Dim FolderPath As String
    Dim RootFolder As String
    Dim Scriptstr As String

    On Error Resume Next
    
    'Enter the Start Folder, Desktop in this example,
    'Use the second line to enter your own path
    RootFolder = MacScript("return POSIX path of (path to desktop folder) as String")
    
    'RootFolder = "/Users/rondebruin/Desktop/TestFolder/"
    
    'Make the path Colon seperated for using in MacScript
    RootFolder = MacScript("return POSIX file (""" & RootFolder & """) as string")
    'Make the Script string
        Scriptstr = "return POSIX path of (choose folder with prompt ""Select the folder""" & _
            " default location alias """ & RootFolder & """) as string"
    
    'Run the Script
    FolderPath = MacScript(Scriptstr)
    On Error GoTo 0
    
    If FolderPath <> "" Then
      With ActiveSheet
         .ExportAsFixedFormat xlTypePDF, Fldr & Application.PathSeparator & .Name, , , 1, , , 0
      End With
    End If
End Sub
but I have no idea if it works as I don't have a Mac.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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