Excel VBA: Save the Active Sheet to Each User’s Desktop
Question details
Save the active Excel sheet as an XLSX file on the current user’s desktop, using a supplied number in the filename.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A macro should save only the active sheet to each user’s desktop, including a redirected desktop, with a filename beginning with Parts List for.
- Observed behavior
- The desired result is a macro-free XLSX file named with a number from cell C6 or an input box, without a macro-free workbook warning.
This macro uses Windows Script Host to find the current user’s desktop, so run it in Excel for Windows. Save the workbook containing the macro as an XLSM file, enable macros if appropriate, and check that the active worksheet has the desired number in cell C6.
Save the active worksheet as an XLSX file on the desktop
Use this Windows VBA macro to take the filename value from cell C6 and save a copy of the active sheet to the current user’s desktop.
The macro looks up the desktop through WScript.Shell, which can resolve a redirected desktop. It copies only the active worksheet into a new workbook and saves that copy as XLSX.
The XLSX copy cannot retain VBA code. Formulas that reference other sheets may become external references.
In Excel, press Alt+F11, select your macro-enabled workbook in the Project pane, and choose Insert > Module.
Paste this code into the module: Sub SaveActiveSheetToDesktop() Dim desktopPath As String Dim fileName As String Dim partNumber As String Dim badChars As Variant Dim ch As Variant Dim newBook As Workbook Dim oldAlerts As Boolean Dim errorMessage As String oldAlerts = Application.DisplayAlerts On Error GoTo CleanFail If TypeName(ActiveSheet) <> "Worksheet" Then MsgBox "Select a worksheet first." Exit Sub End If partNumber = Trim$(CStr(ActiveSheet.Range("C6").Value)) If partNumber = "" Then MsgBox "Enter a number in cell C6." Exit Sub End If badChars = Array("\", "/", ":", "*", "?", """", "<", ">", "|") For Each ch In badChars If InStr(partNumber, CStr(ch)) > 0 Then MsgBox "Cell C6 contains a character that cannot be used in a filename." Exit Sub End If Next ch desktopPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") fileName = desktopPath & "\Parts List for " & partNumber & ".xlsx" If Dir$(fileName, vbNormal Or vbReadOnly Or vbHidden Or vbSystem) <> "" Then MsgBox "A file with this name already exists: " & fileName Exit Sub End If ActiveSheet.Copy Set newBook = ActiveWorkbook Application.DisplayAlerts = False newBook.SaveAs Filename:=fileName, FileFormat:=xlOpenXMLWorkbook newBook.Close SaveChanges:=False Set newBook = Nothing Application.DisplayAlerts = oldAlerts MsgBox "Saved to: " & fileName Exit Sub CleanFail: errorMessage = Err.Description On Error Resume Next If Not newBook Is Nothing Then newBook.Close SaveChanges:=False Application.DisplayAlerts = oldAlerts On Error GoTo 0 MsgBox "The sheet could not be saved: " & errorMessage End Sub
Return to Excel, select the worksheet to export, and check cell C6. Press Alt+F8, select SaveActiveSheetToDesktop, and click Run.
Open the desktop location shown in the confirmation message and check the new Parts List for file. If a file with the same name already exists, change C6 or move the existing file before running the macro again.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday spreadsheet work between applications. The Windows-specific Excel VBA macro above should be run in Excel.

Frequently Asked Questions
Will the macro find a redirected desktop?
WScript.Shell.SpecialFolders("Desktop") retrieves the current user’s desktop path, including a redirected path when Windows reports one. The location must be available and writable.
How do I use an input box instead of cell C6?
In the VBA editor, replace the C6 assignment with partNumber = Trim$(InputBox("Enter the parts list number:")). A blank response stops the macro.
Does the exported XLSX file contain the original macro?
No. XLSX is a macro-free format, so the exported workbook cannot retain VBA code. Keep the source macro in an XLSM workbook.
What happens if the desktop already has a file with the same name?
The macro stops and displays a message instead of overwriting it. Change the value in C6 or move or rename the existing file, then run the macro again.
Why might formulas change in the exported sheet?
Copying only the active worksheet can turn references to other sheets into external references. Open the exported XLSX file and check any formulas that depend on the original workbook.




