Share via

VBA SQL-style import from multiple sources problem Dec 2025

Petruš Dávid 0 Reputation points
2026-01-02T14:53:15.73+00:00

Hello.

I am using SQL-style import in Excel VBA. Example code:

  strConn = "Provider=Microsoft.ACE.OLEDB.16.0;Data SOURCE=" & strFileName & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"";"""
  Set Conn = New ADODB.Connection  'create connection
  Conn.Open ConnectionString:=strConn  'open connection
  Set RS = New ADODB.Recordset
  RS.Open Source:=strSelect, ActiveConnection:=Conn

...used with standard query like:
SELECT * FROM [Sheet1]

...to import data from various sources, including Excel files like xlsx and xlsb.

I encountered problem starting in December 2025, where more complex queries - ones that connect to multiple sources (like two xlsx files) break with Run-time error -2147467259 "Operation is not supported for this type of object."
Example query:
SELECT t1., t2. FROM [Sheet1] AS t1 LEFT JOIN [\path\file2.xlsx].[Sheet2] AS t2 ON t1.[Col1] = t2.[Col2]

(Note: importing from several sheets in the same file works fine, still)

...in this case strFileName would be the path to file1 containing Sheet1 AS t1. I encounter the same problem trying to join multiple csv files in similar fashion, when they are not in the same folder (with augmented strConn, of course). All of this demonstrably worked fine prior to Dec 25.

Testing suggests that import from various sources has been disabled as part of a security update.

My question is: Is there a functioning way to import from various sources without having to do partial imports, copies of files and similar workarounds?

Thank you for your help.

Microsoft 365 and Office | Development | Other

2 answers

Sort by: Most helpful
  1. Michelle-N 16,635 Reputation points Microsoft External Staff Moderator
    2026-01-02T21:43:20.2366667+00:00

    Hi @Petruš Dávid

    Thank you for reaching out to Microsoft Q&A.

    Based on the information you provided, I understand that you are encountering a runtime error when performing SQL-style joins across multiple external files since December 2025, while local queries remain functional.

    After researching the issue, I found the following information for your reference. Based on recent Microsoft Office security changes implemented around late 2025, the ability to perform SQL-style joins between multiple external Excel files (such as .xlsx) via ADODB in VBA may be restricted by default to minimize potential vulnerabilities when processing external data. However, joins within the same file are not affected because they do not trigger the external reference check.

    Microsoft introduced a security setting back in May 2021 that lets admins disable remote database references in Jet Red and the Access Connectivity Engine (ACE). Your change in behavior around December 2025 is likely related to Office security update rollouts in that period (organizations often push hardening policies during monthly security updates).

    You can check your registry to see if Windows has enabled this blocking mode. However, Microsoft clearly warns that enabling AllowQueryRemoteTables (setting it to 1) reduces security and is not recommended unless you fully trust the data source.

    You might also consider using Power Query (Get & Transform), as Power Query allows you to JOIN (Merge) data from multiple different files natively.

    Note:

    • These changes apply on a per-user/per-machine basis. In a corporate environment, administrators can deploy this via Group Policy (look for "Administrative Templates for Office" in the Group Policy Editor).
    • If your setup includes CSV folders in various locations, please ensure the connection string includes the full path, and that those folders are added to Trusted Locations (Trust Center > Trusted Locations).

    I hope the details provided will assist you effectively. Please let me know if you need any further adjustments.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    1 person found this answer helpful.

  2. AI answer

    2026-01-02T14:53:27.47+00:00

    It appears that you are encountering issues with SQL-style imports in Excel VBA when trying to join data from multiple sources, particularly after December 2025. This could be related to changes in security settings or limitations imposed by updates to Excel or the underlying OLEDB provider.

    Here are a few suggestions to work around this issue:

    1. Check for Updates: Ensure that your version of Excel and the Microsoft Access Database Engine are up to date. Sometimes, updates can resolve compatibility issues.
    2. Use Local Copies: If possible, create local copies of the files you need to join and perform the SQL operations on these local files. This can sometimes bypass security restrictions.
    3. Combine Data in Excel: Instead of performing SQL joins directly in your VBA code, consider importing the data from each source into separate sheets in Excel first, and then use Excel formulas or Power Query to combine the data as needed.
    4. Modify Connection String: Ensure that your connection string is correctly formatted and includes all necessary properties. You might want to experiment with different settings in the Extended Properties section.
    5. Use Power Query: If feasible, consider using Power Query for data import and transformation. Power Query is designed to handle data from multiple sources and can be more robust than traditional VBA methods.
    6. Consult Documentation: Review the latest documentation for any changes in how Excel handles OLEDB connections and SQL queries, especially regarding security updates that might affect your current approach.

    If these suggestions do not resolve the issue, you may need to explore alternative methods for data integration or consult with Microsoft support for further assistance.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.