Home
cd ../playbooks
Data & ReportingAdvanced

Excel Automation Workflows

Automate Excel workflows including real-time control, VBA execution, and dashboard updates using xlwings.

10 minutes
By communitySource
#excel#automation#macro#workflow

Every Monday you open the same 5 Excel files, copy data between sheets, update pivot tables, refresh formulas, and email the dashboard. Two hours of clicking that a script could do in 30 seconds — if you knew how to write one.

Who it's for: analysts who repeat the same Excel workflows weekly, finance teams updating dashboards manually, operations managers drowning in spreadsheet updates, business users who want to automate Excel but don't know VBA, anyone who's thought 'there must be a faster way to do this'

Example

"Automate our weekly sales dashboard that pulls from 3 Excel files" → Python script using xlwings that opens your live Excel files, refreshes data from source sheets, updates pivot tables, formats the dashboard, and saves a timestamped copy — scheduled to run every Monday at 8 AM

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

Or install from your terminal:
npx ccplaybooks add excel-automation
# Excel Automation

## Overview

This workflow enables advanced Excel automation using **xlwings** - a library that can interact with live Excel instances. Unlike openpyxl (file-only), xlwings can control Excel in real-time, execute VBA, update dashboards, and automate complex workflows.

## How to Use

1. Describe the Excel automation task you need
2. Specify if you need live Excel interaction or file processing
3. I'll generate xlwings code and execute it

Get new playbooks like this one

One email a week with new Claude Code workflows. Free, like everything here.

No spam. Unsubscribe anytime.

README.md

What This Does

This workflow enables advanced Excel automation using xlwings - a library that can interact with live Excel instances. Unlike openpyxl (file-only), xlwings can control Excel in real-time, execute VBA, update dashboards, and automate complex workflows.


Quick Start

Step 1: Create a Project Folder

mkdir -p ~/Documents/ExcelAutomation

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ~/Documents/ExcelAutomation/

Step 3: Start Working

cd ~/Documents/ExcelAutomation
claude

How to Use

  1. Describe the Excel automation task you need
  2. Specify if you need live Excel interaction or file processing
  3. I'll generate xlwings code and execute it

Example prompts:

  • "Update this live Excel dashboard with new data"
  • "Run this VBA macro and get the results"
  • "Create an Excel add-in for data validation"
  • "Automate monthly report generation with live charts"

Best Practices

  1. Disable Screen Updating: For batch operations
  2. Use Arrays: Read/write entire ranges, not cell-by-cell
  3. Manual Calculation: Turn off auto-calc during data loading
  4. Close Connections: Properly close workbooks when done
  5. Error Handling: Handle Excel not being installed

Examples

Example 1: Live Dashboard Update

import xlwings as xw
import pandas as pd
from datetime import datetime

# Connect to running Excel
wb = xw.books.active
dashboard = wb.sheets['Dashboard']
data_sheet = wb.sheets['Data']

# Fetch new data (simulated)
new_data = pd.DataFrame({
    'Date': pd.date_range('2024-01-01', periods=30),
    'Sales': [1000 + i*50 for i in range(30)],
    'Costs': [600 + i*30 for i in range(30)]
})

# Update data sheet
data_sheet['A1'].value = new_data

# Calculate profit
data_sheet['D1'].value = 'Profit'
data_sheet['D2'].value = '=B2-C2'
data_sheet['D2'].expand('down').value = data_sheet['D2'].formula

# Update KPIs on dashboard
dashboard['B2'].value = new_data['Sales'].sum()
dashboard['B3'].value = new_data['Costs'].sum()
dashboard['B4'].value = new_data['Sales'].sum() - new_data['Costs'].sum()
dashboard['A1'].value = f'Updated: {datetime.now().strftime("%Y-%m-%d %H:%M")}'

# Refresh charts
for chart in dashboard.charts:
    chart.api.Refresh()

print("Dashboard updated!")

Example 2: Batch Processing Multiple Files

import xlwings as xw
from pathlib import Path

def process_sales_files(folder_path, output_path):
    """Consolidate multiple Excel files into one summary."""
    
    app = xw.App(visible=False)
    app.screen_updating = False
    
    try:
        # Create summary workbook
        summary_wb = xw.Book()
        summary_sheet = summary_wb.sheets[0]
        summary_sheet.name = 'Consolidated'
        
        headers = ['File', 'Total Sales', 'Total Units', 'Avg Price']
        summary_sheet['A1'].value = headers
        
        row = 2
        for file in Path(folder_path).glob('*.xlsx'):
            wb = app.books.open(str(file))
            data_sheet = wb.sheets['Sales']
            
            # Extract summary
            total_sales = data_sheet['B:B'].api.SpecialCells(11).Value  # xlCellTypeConstants
            total_units = data_sheet['C:C'].api.SpecialCells(11).Value
            
            # Calculate and write
            summary_sheet[f'A{row}'].value = file.name
            summary_sheet[f'B{row}'].value = sum(total_sales) if isinstance(total_sales, (list, tuple)) else total_sales
            summary_sheet[f'C{row}'].value = sum(total_units) if isinstance(total_units, (list, tuple)) else total_units
            summary_sheet[f'D{row}'].value = f'=B{row}/C{row}'
            
            wb.close()
            row += 1
        
        # Format summary
        summary_sheet['A1:D1'].font.bold = True
        summary_sheet['B:D'].number_format = '$#,##0.00'
        summary_sheet['A:D'].autofit()
        
        summary_wb.save(output_path)
        
    finally:
        app.quit()
    
    print(f"Consolidated {row-2} files to {output_path}")

# Usage
process_sales_files('/path/to/sales/', 'consolidated_sales.xlsx')

Example 3: Excel Add-in with UDFs

Limitations

  • Requires Excel to be installed
  • Limited support on macOS for some features
  • Not suitable for server-side processing
  • VBA features require trust settings
  • Performance varies with Excel version

Installation

pip install xlwings

# For add-in functionality
xlwings addin install

$Related Playbooks

Data & Reporting

GEO Monthly Delta Report

Compare two GEO audits of the same site and generate a client progress report showing exactly what moved, by how much, and what is next

10 minutes
Intermediate
Data & Reporting

GEO Report PDF Renderer

Render a GEO audit markdown file into a styled client-ready PDF with a cover page, color-coded score tables, and severity callouts

10 minutes
Intermediate
Data & Reporting

GEO Client Report Generator

Turn AI-search audit findings into a client-ready GEO report with a weighted 0-100 readiness score and a three-tier action plan

10 minutes
Intermediate
Data & Reporting

Intelligence Report

Generate marketing intelligence briefings.

15 minutes
Intermediate
Data & Reporting

Interactive Dashboard Builder

Build self-contained HTML dashboards with Chart.js for data visualization

10 minutes
Intermediate
Data & Reporting

Funnel Metrics Analyst

Get a daily one-paragraph analysis of your funnel metrics — what moved, what's stalling, and what to do about it. An actual opinion, not a dashboard.

15 minutes
Advanced
Data & Reporting

Live Dashboard

Create live Looker Studio dashboards.

15 minutes
Intermediate
Data & Reporting

Natural Language SQL Writer

Write optimized SQL queries from plain English across multiple database dialects

10 minutes
Intermediate
Data & Reporting

Send Report

Deliver performance reports.

15 minutes
Intermediate
Data & Reporting

Simulate

Simulate revenue impact via Monte Carlo.

15 minutes
Intermediate
Data & Reporting

Google Sheets Automation

Google Sheets automation workflows - data sync, task management, reporting dashboards, and multi-platform integrations

10 minutes
Advanced
Data & Reporting

Table Extraction from Documents

Extract tables from PDF documents with support for merged cells and multi-page layouts using camelot.

10 minutes
Beginner

Browse all Data & Reporting playbooks →