---
title: "Building Custom UFO Tasks: Automating Excel, Word, and Outlook with Natural Language"
description: "Practical examples of automating Microsoft Office applications with UFO — from Excel data manipulation and Word document formatting to Outlook email workflows, with multi-step task descriptions and result verification."
canonical: https://callsphere.ai/blog/building-custom-ufo-tasks-automating-excel-word-outlook-natural-language
category: "Learn Agentic AI"
tags: ["Microsoft UFO", "Office Automation", "Excel", "Word", "Outlook", "Natural Language Tasks"]
author: "CallSphere Team"
published: 2026-03-18T00:00:00.000Z
updated: 2026-05-06T01:02:46.225Z
---

# Building Custom UFO Tasks: Automating Excel, Word, and Outlook with Natural Language

> Practical examples of automating Microsoft Office applications with UFO — from Excel data manipulation and Word document formatting to Outlook email workflows, with multi-step task descriptions and result verification.

## Writing Effective Task Descriptions

The quality of UFO's automation depends heavily on how you describe the task. Vague instructions lead to unpredictable behavior. Specific, step-oriented descriptions produce reliable results.

Here are principles for writing good UFO task descriptions:

- **Be explicit about the target application** — "In Excel" is better than "in the spreadsheet"
- **Describe the end state, not just the action** — "Set cell B5 to the sum of B2 through B4" is better than "do some math in B"
- **Order matters for multi-step tasks** — describe steps in the sequence they should execute
- **Include verification criteria** — "Verify the total in B10 equals 1,500" helps UFO confirm success

## Excel Automation Examples

### Example 1: Data Entry and Formatting

```bash
python -m ufo --task "In the open Excel workbook, go to Sheet1. Enter the following data starting at cell A1: headers are Name, Revenue, Quarter. Row 2 is Acme Corp, 150000, Q1. Row 3 is Beta Inc, 230000, Q1. Row 4 is Gamma LLC, 89000, Q1. Then select the header row and make it bold. Auto-fit all column widths."
```

This task exercises multiple action types: cell navigation, text entry, selection, formatting toolbar interaction, and menu access.

```mermaid
flowchart LR
    INPUT(["User intent"])
    PARSE["Parse plus
classify"]
    PLAN["Plan and tool
selection"]
    AGENT["Agent loop
LLM plus tools"]
    GUARD{"Guardrails
and policy"}
    EXEC["Execute and
verify result"]
    OBS[("Trace and metrics")]
    OUT(["Outcome plus
next action"])
    INPUT --> PARSE --> PLAN --> AGENT --> GUARD
    GUARD -->|Pass| EXEC --> OUT
    GUARD -->|Fail| AGENT
    AGENT --> OBS
    style AGENT fill:#4f46e5,stroke:#4338ca,color:#fff
    style GUARD fill:#f59e0b,stroke:#d97706,color:#1f2937
    style OBS fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
    style OUT fill:#059669,stroke:#047857,color:#fff
```

### Example 2: Formula Creation and Charting

```bash
python -m ufo --task "In the open Excel spreadsheet, add a SUM formula in cell B5 that totals B2 through B4. Format B5 as currency with no decimal places. Then select the range A1 to B4 and insert a bar chart. Move the chart below the data table."
```

### Example 3: Conditional Formatting

```bash
python -m ufo --task "In Excel, select the range B2 to B100. Apply conditional formatting so that cells with values greater than 100000 have a green background and cells with values less than 50000 have a red background."
```

## Automating These Tasks Programmatically

You can also invoke UFO from Python scripts for batch automation:

```python
import subprocess
import json

def run_ufo_task(task: str, timeout: int = 300) -> dict:
    """Run a UFO task and return the result."""
    result = subprocess.run(
        ["python", "-m", "ufo", "--task", task],
        capture_output=True,
        text=True,
        timeout=timeout,
        cwd="C:\\path\\to\\UFO"
    )

    return {
        "returncode": result.returncode,
        "stdout": result.stdout,
        "stderr": result.stderr,
        "success": result.returncode == 0
    }

# Excel automation
excel_tasks = [
    "In Excel, open the file C:\\Reports\\Q1_Sales.xlsx",
    "In Excel, select all data in Sheet1 and sort by column B in descending order",
    "In Excel, create a pivot table from the data in Sheet1 summarizing Revenue by Quarter",
]

for task in excel_tasks:
    print(f"Running: {task}")
    result = run_ufo_task(task)
    if not result["success"]:
        print(f"Task failed: {result['stderr']}")
        break
    print(f"Completed in output: {result['stdout'][-200:]}")
```

## Word Automation Examples

### Example 1: Document Creation

```bash
python -m ufo --task "In Microsoft Word, create a new document. Set the title to Quarterly Business Review. Add three headings: Executive Summary, Financial Highlights, and Next Steps. Under Executive Summary, type a placeholder paragraph. Save the document as QBR_Q1_2026.docx on the Desktop."
```

### Example 2: Formatting and Styles

```bash
python -m ufo --task "In the open Word document, select all text and change the font to Calibri 11pt. Change the title to Heading 1 style. Change all section headings to Heading 2 style. Add page numbers in the footer."
```

## Outlook Automation Examples

```bash
python -m ufo --task "In Outlook, create a new email. Set the To field to finance@company.com. Set the Subject to Q1 Sales Report Ready. In the body type: Hi team, the Q1 sales report has been finalized and is available in the shared drive. Please review by end of week. Best regards. Then click Send."
```

## Multi-Application Workflow: Excel to Outlook

The most powerful UFO use case is chaining actions across applications:

```python
def excel_to_email_workflow():
    """Extract data from Excel and send it via Outlook."""

    # Phase 1: Excel data extraction
    run_ufo_task(
        "In Excel, open C:\\Reports\\Q1_Sales.xlsx. "
        "Go to the Summary sheet. Select cells A1 through D10. "
        "Copy the selection to clipboard."
    )

    # Phase 2: Email composition
    run_ufo_task(
        "In Outlook, create a new email. "
        "Set To to finance@company.com and CC to cfo@company.com. "
        "Set Subject to Q1 Sales Summary. "
        "In the body, type 'Please find the Q1 sales summary below:' "
        "then press Enter twice and paste the clipboard contents. "
        "Click Send."
    )

    print("Excel-to-Email workflow completed")
```

## FAQ

### Can UFO handle Office 365 web versions in the browser?

UFO is designed for native Windows desktop applications, not browser-based Office 365. For web-based Office, browser automation tools like Playwright or Selenium are more appropriate. However, you could use UFO to automate a browser window if the browser exposes proper UIA elements.

### How reliable is UFO for production Office automation compared to COM/VBA?

COM automation via `win32com` or VBA macros is more reliable and faster for repetitive, well-defined Office tasks. UFO is better for tasks that are difficult to script programmatically — such as interacting with complex dialog boxes, formatting charts by visual appearance, or handling dynamic content layouts.

### What happens if an Office application crashes during a UFO task?

If the application crashes, UFO's next screenshot capture will show a different state (perhaps a recovery dialog or a missing window). The HostAgent will detect that the expected application is no longer available and report a task failure. You should implement retry logic in your orchestration script.

---

#OfficeAutomation #ExcelAutomation #WordAutomation #OutlookAutomation #MicrosoftUFO #NaturalLanguageUI #AIWorkflow #DesktopRPA

---

Source: https://callsphere.ai/blog/building-custom-ufo-tasks-automating-excel-word-outlook-natural-language
