OĞUZ EROL · MarkdownTR
Open MarkdownClose
Source: https://oguzerol.com/en/email-excel-attachment-import/

[![Illustrative scenario: a fictional distribution department expects 221 attachments in one quarter from 14 dealers and 3 suppliers; with manual merging, 7 never arrive, 19 arrive late, 6 are duplicates, 5 are corrected resends and 11 have changed columns. In the application to be built, missing senders are listed at Monday 10:00, the same content is never processed twice and a correction replaces the earlier file; 25 rows with text amounts and 2 protected files wait in the error queue.](https://oguzerol.com/gorseller/hizmet-kapaklari/eposta-ekinden-excel-aktarma-webapp-v1-en.webp) View full size](https://oguzerol.com/gorseller/hizmet-kapaklari/eposta-ekinden-excel-aktarma-webapp-v1-en.webp)

# Importing Excel Email Attachments into One Table: Folder, Power Query and a Check Step

[Oğuz Erol](https://oguzerol.com/en/about-me/)  |  12 min read

Getting recurring Excel and CSV email attachments into one table takes four steps: the attachment lands in a folder, the folder’s files are combined, the combined data is checked, and only checked rows reach the master table. Ready-made tools cover the first two: Power Automate saves the attachment to OneDrive or SharePoint and Power Query combines the folder; on Google, Gmail plus Apps Script does the saving. The real work is the third step: who did not send this week, which file arrived twice, which rows were summed in the wrong format. Excel and Power Query suffice for a few senders on one template; without template discipline, with many senders or frequent corrected resends, an application carries the check more safely.

This page covers attachments dealers, branches, suppliers or banks email on a schedule. Reading PDF invoices is covered on the [invoice processing automation](https://oguzerol.com/en/invoice-processing-automation/) page.

## 221 attachments in one quarter: what does copy and paste miss?

The department, the senders and every figure are fictional; each number comes from a Python script and is asserted there. A manufacturer’s distribution department receives a weekly sales and stock workbook from 14 dealers and a delivery list from 3 suppliers, with a Monday 10:00 cut-off. A planner pastes each attachment into the master table. One quarter (13 weeks) looks like this:

| Quarter result | Count |
| --- | --- |
| Expected attachments (17 senders × 13 weeks) | 221 |
| Never arrived | 7 (6 dealers, 1 supplier) |
| Arrived after the cut-off | 19 |
| Column renamed or reordered | 11 (8 renamed, 3 reordered) |
| Same file sent twice | 6 (2 under a different file name) |
| Corrected resend | 5 |
| Header pushed down, password-protected, merged cells | 4, 2, 3 |
| Format mix | 198 .xlsx, 13 .xls, 14 .csv |

At quarter end the master table holds 7,262 rows instead of 7,098. The 164 extra rows are counted twice: 3 of the 6 duplicate files were pasted a second time (104 rows), and 2 of the 5 corrections were added on top of the original instead of replacing it (60 rows). In 3 files where a supplier moved a column, 75 rows landed in the wrong column. Another 58 rows were summed wrongly because of their format: one dealer typed amounts as text with letters after the number, so 30 rows never entered the total, and a supplier whose software uses a decimal comma wrote “7,250” kg, which the workbook read as 7,250 instead of 7.25 in 28 rows, a thousandfold error. Microsoft’s [SUM function page](https://support.microsoft.com/en-us/office/sum-function-043e1c7d-7726-4e80-8f32-07b23e057f89) (read 2026-11-01): SUM ignores text values without an error.

None was noticed that week; all share one cause: manual merging does not record which file arrived, which replaced which, or where each row came from.

## How does an attachment land in a folder: Outlook, Power Automate, Gmail?

Use Power Automate in Microsoft 365 or Apps Script on Google; an Outlook rule alone is not enough. In Microsoft’s [list of Outlook rule actions](https://learn.microsoft.com/en-us/office/vba/outlook/how-to/rules/specifying-rule-actions) I could not find an action that saves an attachment to disk (2026-11-01). A rule moves the message; saving the attachment needs VBA via “start a script”. [New Outlook does not support VBA or macros](https://learn.microsoft.com/en-us/microsoft-365-apps/outlook/get-started/vba-alternatives); Microsoft points to Power Automate.

**Power Automate.** The “When a new email arrives (V3)” trigger takes a folder, sender (From), subject filter, “Only with Attachments” and “Include Attachments” ([connector documentation](https://learn.microsoft.com/en-us/connectors/office365/), 2026-11-01). A OneDrive or SharePoint “Create file” action then writes each attachment to the folder. Do not keep the attachment’s own name: put sender, week, date and time in it (for example `D-04_W12_20261026-0830_sales.xlsx`). A time alone cannot be compared with the cut-off. Later steps read the sender trail only from that name. With many simultaneous emails, `Include Attachments` = Yes can time out; Microsoft recommends No plus `Get Attachment (V2)`.

The [Office 365 Outlook connector documentation](https://learn.microsoft.com/en-us/connectors/office365/) states four limits (2026-11-01): the trigger can miss emails when many arrive at once; with Safe Attachments dynamic delivery it can run twice for one message; .eml, .msg and .ics attachments reach it only inside a .zip; moving a message to another folder does not fire it again. Hence the check step needs a “missing” report and a duplicate check.

**Gmail and Apps Script.** A time-driven script finds messages with a Gmail search such as `from:dealer@example.com has:attachment filename:xlsx newer_than:7d` ([search operators](https://support.google.com/mail/answer/7190)). `GmailMessage.getAttachments()` returns the attachments, `getFrom()` the sender and `getDate()` the receipt time; `Folder.createFile(blob)` writes the attachment to a Drive folder ([Apps Script reference](https://developers.google.com/apps-script/reference/gmail/gmail-message), 2026-11-01). Google’s [quota page](https://developers.google.com/apps-script/guides/services/quotas) (last updated 2026-09-03) caps one execution at 6 minutes and total trigger runtime at 90 minutes a day for consumer accounts and 6 hours for Google Workspace. `addLabel` applies to the thread, not the message, so writing each message ID (`getId()`) to a list is sturdier than labelling.

## How does a folder become one table: Power Query “From Folder”

In Excel, a folder is combined through **Data > Get Data > From File > From Folder**; Microsoft’s [folder import article](https://support.microsoft.com/en-us/office/import-data-from-a-folder-with-multiple-files-power-query-94b8023c-2e66-4f6b-8c78-6a00041c90e4) covers Microsoft 365, 2024, 2021, 2019 and 2016 (read 2026-11-01). The files must share a schema; column order does not matter because matching is by column name. Copy and paste follows position. So the supplier’s 3 reordered files cause no trouble in Power Query, while the dealer’s 8 files that say “Units” instead of “Quantity” do: their 304 rows do not land in the Quantity column.

Power Query builds a sample-file query and a function from it; every step added to the sample query applies to all files ([combine files overview](https://learn.microsoft.com/en-us/power-query/combine-files-overview)). Fix the pushed-down header, renamed column and number format there. `File` is the sample query’s file parameter:

```
let
    Book = Excel.Workbook(File, null, true),
    Raw = Book{0}[Data],
    Position = List.PositionOf(List.Transform(Table.ToRows(Raw), each List.Contains(_, "Product code")), true),
    Trimmed = if Position = -1 then error "Header row not found" else Table.Skip(Raw, Position),
    Headers = Table.PromoteHeaders(Trimmed, [PromoteAllScalars = true]),
    Names = Table.RenameColumns(Headers, {{"Units", "Quantity"}}, MissingField.Ignore),
    Types = Table.TransformColumnTypes(Names, {{"Quantity", type number}, {"Amount", type number}}, "en-US")
in
    Types
```

`List.PositionOf` returns -1 when the header is not found. This query searches every cell of every row: in the scenario it finds position 2 in the 4 files whose header sits two rows down and position 0 in the 3 reordered files. A search of the first column only returns -1 for those 3. I raise an error so such a file is not silently misread. `MissingField.Ignore` skips the rename in files without a “Units” column. For the supplier that uses a decimal comma, open a separate query with culture `"de-DE"`: the same text “7,250” reads as 7.25 under one culture and 7,250 under the other, without any error.

**Skip files with errors** in the combine dialog drops failing files; tick it and nobody sees the missing file. For mixed formats, Microsoft’s [Excel connector page](https://learn.microsoft.com/en-us/power-query/connectors/excel) says two things: .xls needs the Access Database Engine (ACE) provider on the computer, and CSV files should be read with the Text/CSV connector, not the Excel connector. So use one folder or query per format. For CSV, `Csv.Document(File, [Delimiter = ";", Encoding = 65001])` states the delimiter and text encoding explicitly. Compare first .xls totals by hand; ACE can return text or null. Protected files and merged cells go to the list a person reviews in the check step.

## How is the check step built: missing files, row counts, error list?

The check step asks three questions: did every expected file arrive, did each file’s rows reach the master table exactly once, and is every numeric cell a number? Two tables are enough. The **Received** table holds the columns Power Query produces by splitting the file name at `_`; C is one date-time value: A Sender, B Week, C Received at, D File name. The **Expected** table has one row per sender and week: A Sender, B Week, C Cut-off. For status, in D2:

```
=IF(COUNTIFS(Received!A:A,A2,Received!B:B,B2)=0,"Missing",IF(COUNTIFS(Received!A:A,A2,Received!B:B,B2,Received!C:C,"<="&C2)>0,"On time","Late"))
```

In the scenario this returns 7 “Missing”, 19 “Late” and 195 “On time”. Filtered at Monday 10:00, this is the “not received this week” report: 26 sender-weeks, at most 3 in one week. Put `=IF(COUNTIFS(Received!A:A,A2,Received!B:B,B2)>1,"Several files","")` in E2 and 11 rows are flagged: 6 duplicates and 5 corrections. A person decides which replaces which.

In the master table every row carries its sender, week, receipt time and source file: A Sender, B Week, C Received at, D Product code, E Quantity, F Delivery date, G Amount, H Source file. On a check sheet, put the file name in column A and the file’s own row count in B:

```
C2  =COUNTIFS(Master!H:H,A2)
D2  =SUMPRODUCT((Master!H$2:H$20000=A2)*ISTEXT(Master!G$2:G$20000))
```

If C is larger than B, the file was pasted twice. D counts rows where `Amount` stayed text, which happens only in a hand-pasted master table: 5 for the dealer file with text amounts, 0 for a clean file. In the Power Query route the `Types` step turns text such as a number followed by letters into an error cell that ISTEXT does not count; collect those rows with `Table.SelectRowsWithErrors(Types, {"Amount"})` into an error query. ISTEXT also misses the thousandfold kg rows: those cells are numbers. All work in Excel 2016.

## Path, timing and limit: stay in Excel or build an intake endpoint?

Excel and Power Query are enough for one shared template, few senders, rare corrected resends and a weekly sheet check. Then do not spend money on an application.

| Path | When | Limit |
| --- | --- | --- |
| Download and paste by hand | One or two senders, a few files a month | Duplicates, corrections and column shifts leave no trace |
| Power Automate or Apps Script + Power Query + check sheet | Same template, few senders | A new column name or format means editing the query; a person separates corrections |
| Sender portal or attachment-reading intake endpoint | Many senders, no template discipline, frequent corrections | Written scope, a server and maintenance |

If one person keeps up with that weekly, stay in Excel.

## How would the flow work in the application to be built?

The application could have two entry doors. In a sender portal, each dealer uploads through a personal account; header, columns and number format are checked at upload and errors show on the dealer’s screen. With an intake endpoint, email stays as it is; the application picks up attachments from a designated mailbox and applies the same rules.

If taken into scope (to be built, not a ready feature), the same quarter could run like this:

- **Content fingerprint:** content is compared, not the file name; all 6 duplicates, including the 2 with a different name, are skipped.
- **Correction versions:** a later file from the same sender and week replaces the earlier one without deleting it; this covers the 5 corrections.
- **Header and column mapping:** the header is searched in any cell of a row; a “Units → Quantity” mapping waits for approval the first time and becomes a rule after that.
- **Number format per sender:** the decimal-comma supplier’s 26 kg rows are read correctly.
- **Error queue:** 25 text-amount rows from the latest versions go to a separate list; the 2 protected files wait as “could not open”. For every file, passed rows plus error rows must equal the file’s row count.
- **Trail:** for each of the 225 attachments, sender, receipt time, file name and decision are recorded.

AI could be set up only to suggest which column a new header maps to; a person approves, and the model never changes rows. Approval and visibility are set in the scope; queued rows stay out of the master table until fixed.

It could be built to fit your needs; the scope is agreed in writing at the first step. The server (VPS) can be opened in your company’s name; the data is yours, downloadable as Excel or CSV any time. Small and mid-sized teams pay no per-user licence fees; the running cost is the server plus maintenance. The source code sits in a repository you can access, with run instructions, a dependency list and known limitations. The general approach is on the [custom web apps for your team](https://oguzerol.com/en/custom-web-apps-for-your-team/) page.

The first meeting is paid. Bring your sender list and two sample attachments with sensitive details removed, and we start with the scope; write through the [contact page](https://oguzerol.com/en/contact/).

## What I have not verified

- I ran no flow in a real Microsoft 365, Gmail or Excel account; formula and query logic was simulated in the script. The new `List.Contains`, `Table.SelectRowsWithErrors` and ISTEXT claims were not run in Excel either. Reading “7,250” as 7,250 on a dot-decimal setting is also a script assumption.
- I did not test whether a renamed column arrives empty or raises an error. I also did not test how desktop Power Query handles a password-protected file; Microsoft only states that Power Query Online does not support them.
- I found no Google example of converting an .xlsx attachment to Sheets in Apps Script. I did not test whether a new reply in a labelled thread inherits the label.

## Frequently Asked Questions

### Do you need access to everyone’s mailbox?

No: use a separate shared mailbox for attachments. The flow reads only that mailbox; personal correspondence never enters it. Per connector documentation (01.11.2026), the shared-mailbox trigger can skip messages above 50 MB.

### Can bank statements or ERP reports come in through the same flow?

Yes, if the format is fixed and they arrive regularly. A machine-generated file has no hand-added header or merged cells; the main risk is a software update changing the column layout. For a protected statement, where the password lives and who holds it is agreed separately; it never sits in the flow as plain text.

### What happens if a sender pastes the table into the email body instead of attaching it?

The flow on this page does not see it; it expects an attachment. A template attachment or a portal is sturdier.

[Back to top ↑](https://oguzerol.com/en/email-excel-attachment-import/#icerik)

WHAT YOU CAN ASK FOR

## How do I work? Work-hour packages

Tell me about your business and what you need on WhatsApp or by phone; we agree on **a work block of somewhere between 5 and 40 hours** and I start doing what is needed. What you get is not a calendar window: it is net working hours spent directly on your business. I can use 40 hours working three days straight, or deliberately spread it out and finish it over a year: whatever the work calls for. I do not spend my time estimating how long something will take, I spend it doing the work; every hour I spend leaves a lasting result in your business. We keep going for as long as you find it useful.

WORK BLOCKS

## Why not monthly? Does a 40-hour block mean one week?

On a fixed monthly fee both sides are watching the wrong thing: you watch a fixed cost, the other side watches how many more contracts like this they can line up. Working by the hour puts us both in front of the same thing: the real value of the work that got done. I know not having an upfront answer to "how much will this cost in total?" is the natural cost of this model. But instead of paying a fixed fee for months to a setup that is not producing results, you only pay for the qualified time spent on your work: and you see exactly where that time went, start to finish. That is why my clients keep coming back.

- **5 hours**: **300 € + VAT** (60€ per hour) · [Choose this block](https://wa.me/905496546489?text=Hi%2C%20I%27d%20like%20info%20about%20the%205-hour%20work%20block.)

- **10 hours**: **500 € + VAT** (50€ per hour) · [Choose this block](https://wa.me/905496546489?text=Hi%2C%20I%27d%20like%20info%20about%20the%2010-hour%20work%20block.)

- **20 hours**: **800 € + VAT** (40€ per hour) · [Choose this block](https://wa.me/905496546489?text=Hi%2C%20I%27d%20like%20info%20about%20the%2020-hour%20work%20block.)

- **40 hours**: **1,400 € + VAT** (35€ per hour) · [Choose this block](https://wa.me/905496546489?text=Hi%2C%20I%27d%20like%20info%20about%20the%2040-hour%20work%20block.)