Stop Using Excel Macros — Python Can Interact with Excel Right Now

The first thing most people do when they hear 'Python can interact with Excel' is install Anaconda, fire up Jupyter, and try to run import xlwings — then get stuck on COM errors, Excel not launching, or permission popups. That’s the wrong move. You don’t need Excel installed at all to read or write .xlsx files. And you definitely don’t need admin rights.

The Problem

You’ve got a sales report in Q3_Sales_Final.xlsx, saved in C:\Reports\. It has inconsistent headers, blank rows, and merged cells in row 5. Your team needs daily updates pulled into a dashboard — but no one trusts the current VBA script because it crashes every Tuesday after daylight saving time.

Here’s what the raw file actually looks like (first 8 rows of Sheet1):

ABCD
Sales RepRegionQ3 RevenueClose Date
Sarah ChenAPAC$45,2002024-03-15
James RostovEMEA$62,8002024-04-02
Lena ParkNA$39,1502024-05-11
(merged A5:D5)
Diego MendozaLATAM$51,7002024-06-08
Mia TanakaAPAC$48,9002024-06-19
Acme CorpNA$73,2002024-07-03

The Solution

Do this — not in Excel, not in VBA. In a plain text file named clean_sales.py:

  1. Install only what you need: Run pip install pandas openpyxl. No Excel required. No COM. No registry edits.
  2. Read with skiprows and usecols: Pandas handles merged cells by ignoring them — just tell it which rows to skip and which columns to use.
    df = pd.read_excel("Q3_Sales_Final.xlsx", sheet_name="Sheet1", skiprows=[4], usecols="A:D")
  3. Fix date parsing and currency: Convert column D to datetime, strip '$' and commas from C:
    df['Close Date'] = pd.to_datetime(df['Close Date'])
    df['Q3 Revenue'] = df['Q3 Revenue'].str.replace(r'[$,]', '', regex=True).astype(float)
  4. Write cleanly to a new file: Save to Q3_Clean_20240722.xlsx with formatting disabled (no merged cells, no bold headers):
    df.to_excel("Q3_Clean_20240722.xlsx", index=False)

That’s it. No Excel launch. No dialog boxes. Runs in under 0.8 seconds.

Resulting cleaned data (first 7 rows):

ABCD
Sales RepRegionQ3 RevenueClose Date
Sarah ChenAPAC45200.02024-03-15
James RostovEMEA62800.02024-04-02
Lena ParkNA39150.02024-05-11
Diego MendozaLATAM51700.02024-06-08
Mia TanakaAPAC48900.02024-06-19
Acme CorpNA73200.02024-07-03

Going Further

You can go deeper — but only if you need to.

  • Use openpyxl to modify existing Excel files in place: change cell colors, add formulas, freeze panes. Example: wb = load_workbook('report.xlsx'); ws = wb['Summary']; ws['A1'].font = Font(bold=True); wb.save('report.xlsx')
  • Write to multiple sheets in one go: with pd.ExcelWriter('output.xlsx') as writer: df1.to_excel(writer, sheet_name='Raw'); df2.to_excel(writer, sheet_name='Summary')
  • Read password-protected .xlsx? Not possible with pandas. But msoffcrypto-tool + openpyxl works — if you have the password.
  • Surprising tip: Excel files are ZIP archives. Rename data.xlsx to data.zip, extract it, and look inside xl/worksheets/sheet1.xml. That’s how openpyxl reads them — no Excel needed.

When NOT to Use This

Don’t reach for Python if:

  • You need real-time cell-level events (like ‘on change’ triggers). Python can’t listen to Excel UI events — VBA or Office JS can.
  • Your file is .xls (Excel 97–2003 binary format). xlrd dropped support after v2.0. Use pyxlsb for .xlsb, or convert first.
  • You’re running on a locked-down corporate laptop without pip access. Then stick with Power Query — it’s already there, and IT won’t block it.
  • You’re editing files that others have open and locked. Python will throw PermissionError. Excel locks the file. No workaround.

Also: never use xlwings on Linux servers. It requires Excel.app or Excel.exe — which don’t exist there.

Keyboard Shortcuts

These aren’t Excel shortcuts — they’re Python dev shortcuts you’ll use daily:

ActionShortcutNotes
Run current Python scriptCtrl+Shift+F10 (PyCharm)Or F5 in VS Code with Python extension
Open terminal in project folderAlt+F12 (PyCharm)Faster than navigating folders manually
Insert current date in filenameAlt+Shift+DNot native — set up as a macro in your editor (e.g., VS Code snippet)
Toggle Python consoleAlt+4In PyCharm; runs python -i with current environment
Lisa Anderson

Lisa Anderson

Lisa is a certified Microsoft trainer who writes step-by-step guides for Power Automate