If you've ever tried to convert an XLSM file to PDF using an online converter and found your macros missing afterwards, you've discovered one of the most misunderstood limitations in the file conversion space.
This guide gives you the full picture: what actually happens to macros during XLSM to PDF conversion, which tools handle it correctly, and when macro preservation is genuinely impossible.
Here it is upfront: VBA macros cannot be embedded in a PDF file. A PDF is a static document format. It has no execution layer for code.
When people search for "xlsm to pdf keep macros," they usually mean one of three different things — and each has a different solution:
1. Preserve macros in the source file during a batch migration (XLSM stays XLSM) 2. Move macros to a new format that can still run them (XLSM → XLSM/XLSB/XLAM) 3. Document the macro code alongside the PDF output for reference
Understanding which of these you need determines which solution works for you.
CloudConvert, Zamzar, ILovePDF, Adobe Acrobat online — they all strip macros from XLSM files. This isn't a bug. It's a deliberate policy.
Running VBA code server-side on behalf of millions of users creates significant security and liability exposure. VBA macros can execute arbitrary code, access file systems, make network calls, and interact with COM objects. No enterprise SaaS running at scale will accept that risk.
The result: every free online converter strips macros from XLSM files before or during conversion. If your XLSM file has macros that need to survive the conversion workflow, you need a different approach.
The most reliable approach for enterprise batch conversion is Windows COM automation via Python or PowerShell. This uses Excel itself as the conversion engine, which means macro handling is fully faithful — Excel knows how to preserve its own formats.
import win32com.client
import os
def convert_xlsm_batch(input_folder, output_folder, keep_macros=True):
xl = win32com.client.Dispatch("Excel.Application")
xl.Visible = False
xl.DisplayAlerts = False
for filename in os.listdir(input_folder):
if filename.endswith('.xlsm'):
input_path = os.path.abspath(os.path.join(input_folder, filename))
# For PDF output (macros cannot be in PDF — this is the Excel-rendered PDF)
output_pdf = os.path.join(output_folder, filename.replace('.xlsm', '.pdf'))
wb = xl.Workbooks.Open(input_path)
# Export to PDF (visual output — no macros in PDF)
wb.ExportAsFixedFormat(0, output_pdf)
# If you also want to preserve macro-enabled copy:
if keep_macros:
output_xlsm = os.path.join(output_folder, filename)
wb.SaveAs(output_xlsm, FileFormat=52) # 52 = xlOpenXMLWorkbookMacroEnabled
wb.Close(False)
xl.Quit()
FileFormat constants:
51 = xlOpenXMLWorkbook (.xlsx) — strips macros52 = xlOpenXMLWorkbookMacroEnabled (.xlsm) — preserves macros56 = xlExcel8 (.xls) — legacy format, preserves macros0 = ExportAsFixedFormat PDF — visual-only, no macros possibleAspose.Cells is the only cross-platform library that handles macro-aware Excel conversion correctly. It runs on Linux, Mac, and Windows with no Excel dependency.
import aspose.cells as ac
wb = ac.Workbook("input.xlsm")
Save with macros preserved (to XLSM)
save_options = ac.XlsSaveOptions(ac.SaveFormat.XLSM)
wb.save("output.xlsm", save_options)
Export to PDF (macros cannot be in PDF — this is the rendered output)
pdf_options = ac.PdfSaveOptions()
wb.save("output.pdf", pdf_options)
Cost: Aspose.Cells Developer license starts at ~$1,200/year. There is no free tier for production use. The free trial watermarks output files.
For enterprise teams running large-scale migrations, Aspose is the correct answer. For solo founders or small teams, the cost is prohibitive — which is part of why a mid-market solution doesn't exist yet.
LibreOffice can open XLSM files and convert them, but macro handling is inconsistent. LibreOffice Basic (its macro engine) is not VBA-compatible, so VBA macros are not executed and may not be preserved correctly across formats.
Convert XLSM to PDF (macros not preserved in PDF — unavoidable)
libreoffice --headless --convert-to pdf input.xlsm
Convert XLSM to XLSX (macros stripped — LibreOffice doesn't preserve VBA in XLSX)
libreoffice --headless --convert-to xlsx input.xlsm
Convert XLSM to ODS (LibreOffice native — some macro preservation, but VBA → Basic conversion is lossy)
libreoffice --headless --convert-to ods input.xlsm
Reality check: LibreOffice is excellent for simple document conversion. For macro-heavy enterprise workbooks, expect to lose macro functionality. Use it for visual PDF export only.
For single files or small batches, the highest-fidelity option is simply opening the file in Excel and using File → Export → Create PDF/XPS.
This produces the cleanest PDF output (Excel renders it exactly as you see it on screen) and the source XLSM file is unchanged. Zero automation, but zero risk of macro handling bugs.
If your goal is PDF output specifically, macros cannot be preserved — period. PDF has no execution layer.
The closest you can achieve is: 1. Export a high-quality PDF from the workbook (visual rendering, no code) 2. Keep the original XLSM on hand for future editing/re-running macros 3. Export the VBA code to a .bas file as documentation alongside the PDF
To export VBA code programmatically:
import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
xl.Visible = False
wb = xl.Workbooks.Open(r"C:\path\to\file.xlsm")
for component in wb.VBProject.VBComponents:
if component.Type == 1: # vbext_ct_StdModule
code = component.CodeModule.Lines(1, component.CodeModule.CountOfLines)
with open(f"{component.Name}.bas", "w") as f:
f.write(code)
wb.Close(False)
xl.Quit()
This approach is useful for compliance/audit use cases where you need a PDF record of the workbook AND a code archive alongside it.
| Use Case | Best Option | Cost | Platform | |----------|-------------|------|----------| | Single file, highest quality PDF | Manual Excel export | Free (needs Excel) | Windows/Mac | | Batch PDF export, macros not needed | LibreOffice headless | Free | Any | | Batch conversion preserving macros (.xlsm→.xlsm) | COM Automation | Free (needs Excel) | Windows only | | Cross-platform batch, production | Aspose.Cells | $1,200+/year | Any | | Quick online PDF (macros not needed) | CloudConvert/Zamzar | Free tier | Browser |
No. PDF files cannot contain executable code. When you convert XLSM to PDF, the macros cannot be transferred to the PDF format — this is a PDF specification limitation, not a tool limitation.
Online converters deliberately strip macros from uploaded files for security reasons. Executing VBA code server-side creates liability and security risks for platforms serving millions of users. This is a policy decision, not a technical limitation.
For XLSM-to-PDF specifically: no. The PDF format cannot hold macros, so preservation is impossible regardless of the tool. For XLSM-to-XLSM batch migration: COM automation (free, Windows only) or Aspose.Cells (paid) are your options.
XLSM is an Excel Macro-Enabled Workbook. XLSX is a standard Excel Workbook without macro support. Converting XLSM to XLSX strips all VBA macros. If you need the macros to survive, keep the output format as XLSM.
If you're a developer who landed here while researching whether to build a macro-safe conversion tool, the short answer is: the mid-market gap is real.
Enterprise users need this solved. The only reliable tool (Aspose) costs $1,200+/year. A SaaS at $7-15/month with COM automation on Windows or Aspose license cost built into unit economics would be competitive and defensible.
I researched this niche in depth — competitive landscape, search demand, pricing model, technical architecture options, and programmatic SEO plan. If you want the full breakdown:
Macro-Safe Converter Launch Kit — keyword matrix, positioning guide, landing page copy, pricing framework, and 48-hour launch checklist for building in this niche.
Last updated: April 2026
Macro-Safe Converter preserves VBA macros through XLSM conversions. One-time kit — no subscription.
Get the Kit — $9 one-time →