VBA & Macro Problems

Find Video Files in Excel or Access with VBA

Adam DavisAdam Davis Nov 18, 2026 869 views

Question details

Find video files in a folder and its subfolders from Excel or Access without maintaining a list of file extensions.

Find Video Files in Excel or Access with VBA
Product
Microsoft Excel 2019 and Microsoft Access 2019
Device & OS
Windows 10
Scenario
Use VBA to retrieve paths for files that Windows identifies as videos.
Observed behavior
The user wants to retrieve video search results for use in Excel or Access rather than only display them in File Explorer.
Before you start

Check that Windows Search is running and that the target folder is included in the search index. In Windows 10, open Settings > Search > Searching Windows to review indexed locations.

Solution 1Recommended

Query Windows Search for video paths with VBA

Use the Windows Search provider to retrieve indexed video paths without maintaining an extension list.

Windows Search exposes indexed properties through its OLE DB provider. This approach queries files classified as videos, but results depend on indexing and Windows' classification; it is not a guaranteed inventory of every video file.

1
Open the VBA editor

In Excel or Access, press Alt+F11, choose Insert > Module, and paste the macro in the next step.

2
Add the search macro

Paste this code and replace the example folder with the local folder to search, without a trailing backslash: Sub FindIndexedVideos() Dim folder As String, scope As String, sql As String Dim cn As Object, rs As Object folder = "C:\Users\Public\Videos" scope = Replace(Replace(folder, "\", "/"), "'", "''") sql = "SELECT System.ItemPathDisplay FROM SYSTEMINDEX " & _ "WHERE SCOPE = 'file:" & scope & "/' " & _ "AND System.Kind = 'video'" Set cn = CreateObject("ADODB.Connection") cn.Open "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';" Set rs = cn.Execute(sql) Do Until rs.EOF Debug.Print rs.Fields(0).Value rs.MoveNext Loop rs.Close cn.Close End Sub

3
Run and inspect results

In the VBA editor, choose View > Immediate Window, place the cursor inside FindIndexedVideos, and press F5. Copy the printed paths into an Excel worksheet or use them in your Access import code.

4
Check missing results

If expected files are missing, review the folder under Settings > Search > Searching Windows and allow indexing to finish. The SCOPE condition includes indexed subfolders.

Query Windows Search for video paths with VBA
Windows Search limitations: The provider and Windows Search service must be available. A file may be omitted if it is not indexed or Windows does not classify it as a video.
Free Microsoft Office alternative

Review Video File Lists in WPS Spreadsheets

WPS Office is a free, lightweight alternative with a familiar interface for working with file lists and existing Office documents. Paste paths from File Explorer into WPS Spreadsheets; the Windows Search VBA solution itself is specific to Microsoft Office and is not fixed by switching suites.

Paste and organize video file paths in a spreadsheetOpen and save Microsoft Excel XLSX files for easier migrationUse a familiar spreadsheet interfaceWork with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Can VBA directly retrieve File Explorer's video search results?

There is no documented VBA method that returns the results from an open File Explorer search window. You can instead query Windows Search through its provider or maintain your own list of video extensions.

Does the VBA search include subfolders?

Yes. The Windows Search SQL SCOPE condition searches the specified folder and its indexed subfolders.

Why are some video files missing from the results?

The files may not be indexed, or Windows may not classify them as videos. Check Settings > Search > Searching Windows and allow indexing to finish before running the macro again.

Where does the macro put the file paths?

It prints them in the VBA Immediate Window. Open that window with View > Immediate Window or Ctrl+G, then copy the paths or adapt the loop to write them to a worksheet or Access table.