Get Microsoft Entra ID Group Memberships via Microsoft Graph (VBA) #
What this does #
Retrieves the list of Microsoft Entra ID (Azure AD) groups of which the authenticated user is a direct member, using Microsoft Graph with MFA. Returns all group types — Security, Microsoft 365, and Distribution groups. Results are sorted alphabetically. Handles Graph API result paging automatically so all groups are returned regardless of how many the user belongs to.
Office apps #
- Access (tested M365)
- Excel (untested M365)
Required components #
- VBAuth.dll v1.x
- modVBAuthGlobalConstants.bas (from /shared)
- modGetMyGroups.bas (this module)
- JSONConverter.bas (Tim Hall VBA-JSON — https://github.com/VBA-tools/VBA-JSON)
Azure Entra App Registration #
Delegated permissions:
- GroupMember.Read.All
VBAuth Admin Table – Required Values #
| Column Name | Required Value / Example | Notes |
|---|---|---|
| AppID | 5 | Identifies this feature’s configuration record |
| ActionName | VBAuth – Get My Groups | Display name — any value acceptable |
| ClientID | (your App Client ID) | GUID from Azure App Registration Overview blade |
| TenantID | (your Tenant ID) | GUID from Azure App Registration Overview blade |
| ObjectID | (your Object ID) | Set by PopulateMissingObjectIDs |
| ScopeClaims | GroupMember.Read.All | Comma-separated Graph scopes |
| Verb | GET | HTTP method |
| URLPart1 | https://graph.microsoft.com/v1.0/me/memberOf | Graph endpoint |
| URLParameter1 | NO VALUE REQUIRED | Not used |
| URLPart2 | NO VALUE REQUIRED | Not used |
| URLParameter2 | NO VALUE REQUIRED | Not used |
| URLPart3 | NO VALUE REQUIRED | Not used |
| WaitForLogin | 60 | Seconds — NB MSXML2 timeout parameters are in milliseconds |
Module: modGetMyGroups.bas #
Public function #
GetMyGroups(ByRef strGroupList As String, ByRef lngGroupCount As Long) As Boolean
Code language: PHP (php)
Acquires a bearer token for the configured AppID, then calls the Graph /me/memberOf endpoint. Follows @odata.nextLink pagination until all pages are retrieved. Returns True on success. Returns False on any HTTP error or authentication failure, with strMessage (from modVBAuthGlobalConstants.bas) containing the error detail.
On return, strGroupList contains the group display names as a newline-delimited string, sorted alphabetically. lngGroupCount contains the total number of groups returned.
Behaviour #
- Returns direct group memberships only — nested group memberships are not resolved
- All group types are returned: Security, Microsoft 365, and Distribution groups
- Groups without a
displayNamein the Graph response are silently skipped - Results are sorted alphabetically using a bubble sort — acceptable for typical group counts
- Handles Graph API paging via
@odata.nextLink— all pages are retrieved in a single call - A network timeout returns a descriptive error message — timeout duration is controlled by
lngHTTPTimeoutinmodVBAuthGlobalConstants.bas - Requires interactive sign-in — application permissions are not supported
Notes #
- Does not support application permissions
- Returns direct memberships only — does not recurse into nested groups
VBAuth, developed and maintained by Andrew Richards (The IT Service Ltd) and Peter Bryant (Corylus Business Systems), © 2025–2026. All rights reserved. https://vbauth.com