Forum Discussion
Mail Outlook dans Excel avec PowerQuery
- Anonymous2 years ago
Hi Agreement6 ,
What @watkinnc said is correct, if you want to connect to Outlook you need to use the exchange connector
Please look at my test screenshots below to see if you are doing anything incorrectly during the connection process:
Get data > From Other Sources > From Microsoft Exchange:Enter your Outlook email account and authenticate it:
Then you can select the table you need:
And the final output:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - Anonymous2 years ago
Hi Agreement6 ,
You'll need a subscription that already includes Exchange, which is one of the Business plans.
This case which has been solved may be helpful to you:
Solved: We Couldn't Authenticate With The Credential Provi... - Microsoft Fabric Community
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Tracking Outlook emails in Excel or Power BI using Power Query involves connecting to your Outlook mailbox and extracting relevant email data. This process is typically performed using the Outlook API or an intermediary service that can access your email data. Here’s a detailed guide on how to achieve this:
- Using Power Query in Excel
Note: Direct integration of Outlook emails in Power Query is not supported natively in Excel. Instead, you can use VBA (Visual Basic for Applications) to extract email data and then load it into Excel. Here’s how:
Step 1: Use VBA to Export Emails to Excel
- Open Excel.
- Press Alt + F11 to open the VBA editor.
- Insert a New Module:
- Go to Insert > Module.
- Paste VBA Code:
- Use the following VBA code to extract email data from Outlook and write it to Excel:
Sub ExportEmailsToExcel()
Dim olApp As Object
Dim olNs As Object
Dim olFolder As Object
Dim olMail As Object
Dim i As Integer
Dim ws As Worksheet
' Create a new worksheet
Set ws = ThisWorkbook.Sheets.Add
ws.Name = "EmailData"
ws.Cells(1, 1).Value = "Subject"
ws.Cells(1, 2).Value = "From"
ws.Cells(1, 3).Value = "Received Time"
ws.Cells(1, 4).Value = "Body"
' Initialize Outlook application
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olFolder = olNs.GetDefaultFolder(6) ' Inbox
' Loop through emails
i = 2
For Each olMail In olFolder.Items
ws.Cells(i, 1).Value = olMail.Subject
ws.Cells(i, 2).Value = olMail.SenderName
ws.Cells(i, 3).Value = olMail.ReceivedTime
ws.Cells(i, 4).Value = olMail.Body
i = i + 1
Next olMail
' Cleanup
Set olMail = Nothing
Set olFolder = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
- Run the VBA Code:
- Press F5 to run the code and export email data to Excel.
- Save the Excel File:
- Save your Excel file with the extracted email data.
Step 2: Load Data into Power BI
- Open Power BI Desktop.
- Click on Get Data.
- Choose Excel and select the file where you saved the email data.
- Load the Data:
- Select the relevant worksheet and load the data into Power BI for further analysis.
- Using Power Query in Power BI
Direct access to Outlook data is not supported natively in Power Query either. However, you can use Microsoft Graph API or third-party connectors to fetch email data.
Option 1: Microsoft Graph API
- Register an App in Azure AD:
- Go to the Azure portal.
- Register a new application to get the Client ID and Secret.
- Use Microsoft Graph API to Access Emails:
- You will need to set up API permissions for accessing Outlook emails.
- You can use Microsoft Graph API endpoints like /me/messages to get email data.
- Connect Power BI to Microsoft Graph API:
- Use Web connector in Power BI to call the Graph API and pull email data.
- You might need to handle authentication and API request formatting.
- Transform and Load Data:
- Use Power Query to transform the JSON response and load the data into Power BI.
Option 2: Third-Party Connectors
- Explore Third-Party Tools:
- There are third-party tools and connectors like Power Automate or Zapier that can help automate the extraction of email data from Outlook to a storage solution like SharePoint or SQL Server.
- Set Up a Flow:
- Use Power Automate to create a flow that extracts email data and stores it in a database or file accessible by Power BI.
- Connect Power BI to Data Source:
- Use Power BI to connect to the data source where email data is stored (e.g., SQL Server, SharePoint).