Office Scripts + Power Automate (Excel Automation in the Cloud)
Phase 3 goal
Replace manual chasing, copying, and emailing with flows that move data between Excel, SharePoint, Teams/Outlook, and Power BI, and that alert people when program metrics cross thresholds.
Licensing note: Standard connectors (SharePoint, Excel Online (Business), Outlook, Teams, Approvals, Power BI) come with most Microsoft 365 licenses. Premium connectors (e.g., HTTP, SQL, Dataverse in some cases) need extra licensing. Your environment may also have DLP policies that block some connector combinations. Check your tenant before you design.
π― Learning objectives
Tick each one when you can actually do it.
π‘ Key concepts
- Office Scripts: Excel on the web automation (Automate tab). The Action Recorder writes the code for you, and you edit it in the Code Editor. Saved to OneDrive/SharePoint, so it works with flows (VBA doesn't run in cloud flows).
- Script with parameters and a return value:
function main(workbook: ExcelScript.Workbook, threshold: number): string[] { const table = workbook.getTable("EVMSnapshot"); const values = table.getRangeBetweenHeaderAndTotal().getValues(); const headers = table.getHeaderRowRange().getValues()[0] as string[]; const iProg = headers.indexOf("ProgramID"); const iCPI = headers.indexOf("CPI"); const flagged: string[] = []; values.forEach(r => { if ((r[iCPI] as number) < threshold) flagged.push(r[iProg] as string); }); return flagged; } - Run script action in Power Automate passes
thresholdand receivesflaggedas dynamic content. - Tool choice:
Need Best tool Reshape and clean incoming data Power Query Format, rearrange, or stamp a workbook in the cloud on a schedule Office Scripts + Power Automate Desktop-only legacy macros VBA (not callable from cloud flows) Heavy transforms, Word/Excel document generation, complex logic Python (Phase 4)
π Hands-on exercise: Format-and-Stamp Script
Data: An Excel workbook in OneDrive with Table EVMSnapshot (ProgramID, ProgramName, CPI, SPI, CV, SV, EAC, VAC, PeriodEnd).
- Record a script that applies number formats, freezes the header row, applies RAG fill to CPI/SPI, and stamps "Generated:
" in a header cell. - Edit the code so thresholds are parameters.
- Build a flow: scheduled monthly β Run script β email the workbook link to yourself.
π¦ Mini-project: Flagged Programs Digest
Use the parameterized script above (returns an array of flagged programs) in a flow that builds an HTML table of flagged programs (Select + Create HTML table) and emails a digest to a distribution list only when at least one program is flagged (length(...) > 0).
π§ Self-check quiz
Answer in your own words, then check. Grade yourself honestly; your score is saved.
main function returns a value (e.g., string[] or an object), which shows up as dynamic content in the Run script action's output.