Save an Excel VBA Export to Any Windows User’s Desktop
Question details
Find the current Windows user's Desktop folder in VBA so a macro can save or export a file without a hard-coded username.

- Product
- Microsoft Excel
- Device & OS
- Windows
- Scenario
- An Excel macro needs to export a file to the Desktop when run by different Windows users.
- Observed behavior
- The macro should resolve the current user's Desktop path and use it as the export destination.
Open the workbook you want to export and make sure the current Windows user can write to the Desktop. Enable macros only for a workbook you trust.
Use WScript.Shell to export a PDF to the current user's Desktop
Use this Windows VBA method to retrieve the Desktop path dynamically before exporting the active workbook as a PDF.
In Excel, press Alt+F11, then select Insert > Module.
Paste this code into the module: Sub ExportToDesktop() Dim desktopPath As String desktopPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=desktopPath & "\Report.pdf" End Sub
Return to Excel and activate the workbook you want to export. Press Alt+F8, select ExportToDesktop, and click Run. Check the Desktop for Report.pdf.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility for an easier transition. Check VBA availability and test macros before relying on the same code in WPS.

Frequently Asked Questions
Does this code work if the Desktop is redirected?
SpecialFolders("Desktop") asks Windows for the current user's Desktop location instead of constructing a path from the username. The returned location must still be available and writable.
How do I keep the macro in my workbook?
In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). Enable macros only when you trust the workbook.
Can I change the PDF filename?
Yes. In the Filename argument, replace "\Report.pdf" with a backslash followed by your preferred filename, such as "\Sales.pdf".
Will this VBA code work on a Mac?
The WScript.Shell method is specific to Windows. Excel for Mac requires a different way to locate the user's Desktop.




