README Search Files (Search API) #
Overview #
Searches for files across OneDrive for Business and SharePoint document libraries simultaneously using the Microsoft Search API. Authentication is via OAuth2 with MFA support using VBAuth.dll. The two sources cannot be separated at the API level — results are always combined.
Two search modes are available via radio button: Name only (server-side KQL filename: prefix) and Name and content (full-text index search). ContentType:Document is added to all queries to exclude folders, site pages, and news from results.
Results display filename, last modified date, last modified by, and the web URL of each file. Up to 25 results are returned per search; if more exist a note is appended to the output.
Office apps #
- Access (tested M365)
- Excel (untested M365)
Required components #
- VBAuth.dll v1.x
- modVBAuthGlobalConstants.bas (from /shared)
- modSearchFilesSearchAPI.bas (this module)
Azure Entra App Registration #
Delegated permissions:
- Files.Read.All
Note: Files.Read is insufficient for POST /search/query — it returns HTTP 403. Files.Read.All is the minimum required scope for this endpoint. Admin consent is required before users can authenticate.
Note: POST /search/query requires a work or school M365 account. It does not support personal Microsoft accounts (MSA).
VBAuth Admin Table – Required Values #
| Column Name | Required Value / Example | Notes |
|---|---|---|
| AppID | 26 | Identifies this feature’s configuration record |
| ActionName | VBAuth – Search Files (Search API) | 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 | Files.Read.All | Comma-separated Graph scopes |
| Verb | POST | HTTP method — Graph Search API uses POST |
| URLPart1 | https://graph.microsoft.com/v1.0/search/query | Graph Search API 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: modSearchFilesSearchAPI.bas #
Public functions #
Public Function SearchFilesSearchAPI( _
ByVal strTerm As String, _
ByVal intSearchMode As Integer, _
ByRef strResult As String, _
ByRef strMessage As String) As Boolean
Code language: JavaScript (javascript)
Builds and POSTs a JSON search request to POST /search/query with entityTypes: ["driveItem"]. intSearchMode 1 = name only (KQL filename: prefix), 2 = name and content. Returns True on success. strResult receives the formatted display text. strMessage receives a summary on success or error description on failure.
Private functions #
SafeString— returns a string field from a parsed JSON Dictionary, returning""for absent fields without error.SafeNestedString— reads a value from a two or three level nested Dictionary safely.BuildQueryString— constructs the KQL query string for the selected search mode.
Behaviour #
- Runs as the signed-in user (delegated permissions).
- HTTP 200 is the success code.
- Results cover both OneDrive for Business and SharePoint document libraries combined. There is no supported API mechanism to restrict results to one source only.
ContentType:Documentis appended to all queries to exclude folders, SharePoint site pages, and news items.- Name only mode uses the KQL
filename:prefix which is a server-side filter — only files whose name matches are returned. - Name and content mode searches the full-text index — files matching in either name or content are returned.
- Up to 25 results are returned per call (
size: 25in the request body). If the total exceeds 25 a note is appended to the output. - The
hitskey is absent in the response when zero results are found. This is guarded withOn Error Resume Next+Is Nothingcheck. - Authentication is interactive on first run; subsequent calls within the session reuse the cached token.
Notes #
Files.Read.Allis the minimum required scope —Files.Readreturns HTTP 403 for this endpoint.- Admin consent is required before users can authenticate.
- This endpoint does not support personal Microsoft accounts (MSA) — it requires a work or school M365 account.
- This feature uses a separate Entra app registration from the Drive API search feature (AppID 27) so that a developer taking only this feature uses the correct minimum scope.
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