Create an XLSX File with Values and Formatting Using Excel VBA
Question details
Create a new XLSX workbook from the current worksheet, preserving its displayed values and formatting without retaining formulas or external links.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user wants to export the current worksheet as a standalone workbook using VBA.
- Observed behavior
- The new workbook should contain pasted values and formatting rather than formulas linked to the source workbook.
Open the source workbook in Excel and select the worksheet you want to export. Recalculate the workbook if needed so the copied formula results are current, and make sure macros are enabled.
Export the active worksheet with an Excel VBA macro
Use this macro to create a one-sheet XLSX file containing the active worksheet’s values, cell formats, and column widths.
The macro copies the used range to the same cell positions in a new workbook. Formulas are pasted as their current results, and Excel workbook links found in the new file are broken before saving.
Cell formats can include conditional formatting rules that use formulas. Review those rules and any remaining links if the exported file must contain no external references.
In Excel, select the source worksheet, then open the VBA editor from Developer > Visual Basic. If the Developer tab is unavailable, open the VBA editor with your Excel shortcut.
In the VBA editor, choose Insert > Module and paste this code: Sub ExportValuesAndFormats() Dim sourceSheet As Worksheet Dim sourceRange As Range Dim newBook As Workbook Dim targetRange As Range Dim savePath As Variant Dim links As Variant Dim i As Long Set sourceSheet = ActiveSheet Set sourceRange = sourceSheet.UsedRange savePath = Application.GetSaveAsFilename( _ InitialFileName:="Export.xlsx", _ FileFilter:="Excel Workbook (*.xlsx), *.xlsx") If savePath = False Then Exit Sub Set newBook = Workbooks.Add(xlWBATWorksheet) Set targetRange = newBook.Worksheets(1).Range(sourceRange.Address) sourceRange.Copy targetRange.PasteSpecial Paste:=xlPasteValues targetRange.PasteSpecial Paste:=xlPasteFormats targetRange.PasteSpecial Paste:=xlPasteColumnWidths Application.CutCopyMode = False links = newBook.LinkSources(Type:=xlLinkTypeExcelLinks) If IsArray(links) Then For i = LBound(links) To UBound(links) newBook.BreakLink Name:=links(i), Type:=xlLinkTypeExcelLinks Next i End If newBook.SaveAs Filename:=CStr(savePath), _ FileFormat:=xlOpenXMLWorkbook End Sub
Return to the source worksheet, choose Developer > Macros, select ExportValuesAndFormats, and click Run. Choose a location and XLSX filename in the Save As dialog.
Open the saved XLSX file and inspect a few cells in the formula bar to confirm they contain values. Check Data > Edit Links or Workbook Links, depending on your Excel version, and review Home > Conditional Formatting > Manage Rules for unwanted external references.

Work with exported Excel files in WPS Spreadsheet
WPS Office is a free, lightweight alternative for opening and editing spreadsheet files. Its familiar interface and Microsoft Office format compatibility make it easy to move existing workbooks into WPS.

Frequently Asked Questions
Does the exported XLSX contain the original formulas?
No. The macro uses PasteSpecial with xlPasteValues, so worksheet formulas are replaced by their current results. Conditional formatting rules may still contain formulas.
How do I export a different worksheet?
Select the desired worksheet in Excel before running Developer > Macros > ExportValuesAndFormats. The macro uses the active worksheet as its source.
Why should I recalculate before running the macro?
The macro copies the current results of formulas, not the formulas themselves. Recalculate the workbook first if those results may be out of date.
How can I check for remaining external references?
In the exported workbook, check Data > Edit Links or Workbook Links, depending on your Excel version. Also inspect Home > Conditional Formatting > Manage Rules and remove or change any rules that refer to external workbooks.
Will the macro be saved in the new XLSX file?
No. The new file is saved as a standard XLSX workbook, which does not store VBA macros. Keep the macro in a macro-enabled workbook if you want to run it again.




