Consulting

Results 1 to 4 of 4

Thread: Query Table in Excel

  1. #1
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location

    Query Table in Excel

    Hello all, i have excel file that i have tons of query table link from an access database. Now that the database location have change, this there a way in vba to change the datasource for all these query tables or i just have to do it one by one?

    thanks

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    If they are truly linked tables, then you can click Tools-> Database Utilities-> Linked Table Manager. It will allow you to update them faster than relinking them by hand.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    VBAX Tutor
    Joined
    Dec 2008
    Posts
    244
    Location
    i think you're talking about access now, this is in excel. I can't find Database Utilities under tools in excel.

  4. #4
    VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    I've moved this thread to the Excel board.

    You'll need to enter the full paths for the original database and the new database.

    [vba]
    Sub RelinkQueries()
    Dim qt As QueryTable
    Dim sh As Worksheet
    Dim strConnect As String

    Const cstrDB_Old As String = "C:\Folder\OLD.mdb"
    Const cstrDB_New As String = "C:\Folder\NEW.mdb"

    For Each sh In ActiveWorkbook.Worksheets
    For Each qt In sh.QueryTables
    strConnect = qt.Connection
    strConnect = Replace(strConnect, cstrDB_Old, cstrDB_New)

    qt.Connection = strConnect
    qt.Refresh
    Next qt
    Next sh
    End Sub
    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •