macro to save sheet as pdf on desktop regardless of user

skf786

Board Regular
Joined
Sep 26, 2010
Messages
156
Hi,

Want to save active sheet only, want to save as PDF and would like the file to open in pdf once it is saved, on the desktop, regardless of user. Thanks for your help in advance!!

Ive got very very limited know how of <acronym title="visual basic for applications">VBA</acronym>!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
There are a bunch of "Special Folders" that you can use. Read more here: https://msdn.microsoft.com/en-us/library/0ea7b5xe(v=vs.84).aspx
Code:
Sub DoPDF()
Dim sName$
Dim Path$


sName = ActiveSheet.Name


Path = CreateObject("WScript.Shell").specialfolders("Desktop")
On Error Resume Next
ThisWorkbook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=Path & "\" & sName & ".pdf", _
    OpenAfterPublish:=True
If Err.Number > 0 Then MsgBox "Error saving pdf."
End Sub
 
Upvote 0
Try this:
Code:
Sub Test()
    With ActiveSheet
        .ExportAsFixedFormat 0, Environ("USERPROFILE") & "\Desktop\" & _
            .Name & ".pdf", OpenAfterPublish:=True
    End With
End Sub
 
Upvote 0
calcsux! this is awesome! thanks so much. My desired file name is in cell e5. Plus I would like dd/mm/yyyy in the file name as well. :)
 
Last edited:
Upvote 0
Thanks Tetra 201! My desired file name is in cell e5. Plus I would like dd/mm/yyyy in the file name as well. :). Thanks in advance!
 
Upvote 0
Thanks Tetra 201! My desired file name is in cell e5. Plus I would like dd/mm/yyyy in the file name as well. :). Thanks in advance!
Here is the code as requested -- except: you cannot have a "/" in the file name.
Code:
Sub ExportPDF()
    With ActiveSheet
        .ExportAsFixedFormat 0, Environ("USERPROFILE") & "\Desktop\" & _
            .Range("E5").Value & "_" & Format(Date, "dd-mm-yyyy") & ".pdf", OpenAfterPublish:=True
    End With
End Sub
 
Last edited:
Upvote 0
To make it even more user friendly: would like to add an 'email report' button which attaches the active sheet as pdf to a new email. Subject of the email shall be taken from cell p6 in the sheet. email address shall be taken from p7. However I would not like the email to be sent without the user pressing the send button. Would like to allow them to add text of their choice in the email. The email shall go through outlook of the respective users as the file is being shared with users in different locations.

Again, thanks so much for everything!
 
Upvote 0
To make it even more user friendly: would like to add an 'email report' button... The email shall go through outlook...
At the moment, I am unable to test any Outlook-related code. So, I cannot help you with this project. Hopefully somebody else will chime in on this.
 
Upvote 0

Forum statistics

Threads
1,214,573
Messages
6,120,318
Members
448,956
Latest member
Adamsxl

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