VBA & Macro Problems

Save an Excel VBA Export to Any Windows User’s Desktop

Rana GarciaRana Garcia Dec 2, 2026 868 views

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.

Save an Excel VBA Export to Any Windows User’s Desktop
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, press Alt+F11, then select Insert > Module.

2
Add the export macro

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

3
Run the macro

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.

Use WScript.Shell to export a PDF to the current user's Desktop
Check the destination and active workbook: The Desktop must be available and writable. ActiveWorkbook refers to the workbook currently active in Excel; change the filename in the code if needed.
Free Microsoft Office alternative

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.

Open and edit Microsoft Excel XLSX and XLS filesExport spreadsheet content to PDFNavigate a familiar spreadsheet interfaceUse a free, lightweight office suite
microsoft office alternative - wps office

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.