Database connection in VBA


New Member
Mar 4, 2019
Newbie question: In a project with a number of subroutines and functions that query and update a database, is there an advantage (or disadvantage) to having just one global database connection that is opened upon initialization of the project and stays open until the project is closed?

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Jerry Sullivan

MrExcel MVP
Mar 18, 2010
The advantage is that the code might run somewhat faster. The disadvantage is it might lose the connection so the code becomes more complex as you need to validate the connection each time you use it and restore it if it has been lost.

You might consider using Power Query to import and transform your data. I haven't used VBA queries since I started using PQ. It' relatively easy to learn (easier than VBA).
Last edited:


New Member
Mar 4, 2019
Many thanks for the helpful reply. Unfortunately, I have to stick with VBA in this case.

Forum statistics

Latest member
Sanjana Ramesh

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...