Microsoft Graph API with Maria Barnes

With Microsoft actively removing COM/VBA support from "New Outlook," Maria Barnes' Graph API solution offers Access developers a forward-compatible pathway to maintain email integration when traditional Outlook automation becomes unavailable.

In her presentation at Access DevCon Vienna, Microsoft MVP Maria Barnes demonstrated how to integrate Microsoft Graph API with VBA applications, providing a robust method to interact with Microsoft 365 services like Outlook and Microsoft Entra ID (formerly Azure Active Directory). Her solution, published as an open-source project on GitHub, offers Access developers a way to create, read, and manage emails, calendar events, and contacts programmatically through authenticated API calls rather than through traditional automation.

Whether you're looking to send automated emails after reports are generated, manage contacts from your Access application, or integrate calendar functionality into your database, this technical deep dive provides the foundation you need to leverage Microsoft's powerful cloud services through the Graph API.

Understanding Microsoft Graph API

What is Microsoft Graph?

  • Gateway to data and intelligence in Microsoft cloud services
  • Connects to Microsoft 365 platform components (Outlook, SharePoint, OneDrive, etc.)
  • Named for how it creates connections between different services
  • Completely unrelated to charting in Access

Available Functionality

  • Email operations (create drafts, send messages)
  • Calendar management (create events)
  • Contact management (retrieve and create contacts)
  • User management through Microsoft Entra ID
  • Many other Microsoft 365 services accessible through the same API

Authentication: The Most Challenging Part

Microsoft Entra ID Setup

  • Requires administrative access to Microsoft Entra ID
  • Need one of these roles: Application Administrator, Application Developer, or Cloud Application Administrator
  • Application must be registered in Microsoft Entra ID portal
  • Registration generates Client ID and Tenant ID needed for authentication

Six-Step Setup Process

  1. Go to Microsoft Entra ID in portal.azure.com
  2. Add an app registration with a descriptive name
  3. Copy the Client ID and Tenant ID values
  4. Add a redirect URI
  5. Select "Mobile and desktop applications" platform
  6. Choose the "Microsoft online native client" for OAuth 2.0

Authentication Flow

  • Two-step process to acquire a token:
    1. Authenticate with Microsoft to get an authorization code
    2. Exchange that code for a token
  • Uses an Edge browser control for the authentication process
  • Tokens expire after 60-90 minutes
  • Project includes logic to automatically refresh expired tokens

Technical Implementation

Project Components

  • Graph Authenticator class module (adapted from Tim Hall's VBA Web Tools)
  • Graph module for API calls
  • Edge browser control for authentication
  • Admin table to store configuration settings
  • Forms to demonstrate API functionality

Key Functions Implemented

  • Create draft email message
  • Send email message
  • Create calendar event
  • List all contacts from a specific folder
  • Get folder ID
  • Create a contact

Usage Pattern

  1. Call a Graph API function
  2. Function triggers authentication if needed
  3. Authentication returns a token
  4. Token is used to make the actual API call
  5. JSON response is processed and converted to usable data

JSON Handling

Sample Use Cases

Email Management

  • Send automated emails after reports run
  • Notify users when workflow statuses change
  • Create draft emails programmatically

Contact Management

  • Synchronize contacts between Access and Outlook
  • Retrieve contact information for use in applications
  • Create new contacts from Access data

Calendar Integration

  • Create appointments based on Access data
  • Schedule events programmatically
  • Integrate with business workflows

Limitations and Considerations

Current Constraints

  • Requires Microsoft 365/Exchange Online (won't work with Gmail/Google Workspace)
  • May have issues with multi-factor authentication
  • Draft messages appear in Outlook but don't automatically open
  • Token lifetime is limited (60-90 minutes)

Technical Requirements

  • Edge browser must be available
  • Access to Microsoft Entra ID for initial setup
  • Proper permissions in the Microsoft 365 environment

Resources and Documentation

Available Resources

  • GitHub repository with complete source code
  • Microsoft Graph API reference documentation
  • Sample code for each API function
  • Tim Hall's VBA Web Tools for additional reference

Finding API Documentation

  • Microsoft's Graph API explorer
  • API reference with examples at graph.microsoft.com
  • Documentation includes required permissions and sample JSON

Conclusion

Maria Barnes' Graph API integration demonstrates a powerful alternative to the Outlook Object Model for Access developers needing to interact with Microsoft 365 services. By leveraging modern authentication and REST API calls, this approach provides a more robust and flexible way to work with emails, contacts, and calendar events directly from Access applications while avoiding many of the pitfalls of traditional Outlook automation.

Access to Recordings

This presentation was part of Access DevCon Vienna, a paid online conference for Microsoft Access developers. The full recording and other conference materials are exclusively available to registered attendees of the conference.

If you attended Access DevCon Vienna, you should have received an email from the conference organizers with a link to the videos.

Consider Attending Future Conferences

The quality and depth of content from Access DevCon Vienna demonstrates the value of professional development conferences focused on Microsoft Access. Consider attending future conferences to:

  • Learn advanced techniques directly from expert presenters
  • Gain access to exclusive content not available elsewhere
  • Ask questions of expert presenters and other attendees
  • Stay current with the latest Access development trends and best practices

For information about upcoming Access DevCon Vienna conferences, visit donkarl.com.

Referenced GitHub Projects

GitHub - mbarnesatbbs/VBA-MicrosoftGraph: Interface with the Microsoft Graph WEB API with VBA
Interface with the Microsoft Graph WEB API with VBA - mbarnesatbbs/VBA-MicrosoftGraph
GitHub - VBA-tools/VBA-JSON: JSON conversion and parsing for VBA
JSON conversion and parsing for VBA. Contribute to VBA-tools/VBA-JSON development by creating an account on GitHub.
GitHub - VBA-tools/VBA-Web: VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web
VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web - VBA-tools/VBA-Web

Acknowledgements

  • Initial draft generated by Claude-3.7-Sonnet