+ Reply to Thread
Results 1 to 3 of 3

How do I modify a QueryTable connection string before it executes?

  1. #1
    Registered User
    Join Date
    02-03-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    2

    How do I modify a QueryTable connection string before it executes?

    A recent server change in our office has exposed many Excel Workbooks with connection strings to obtain external data. Unfortunately, the hard-coded references are now broken so I thought I'd be smart and write a macro to change them all. I tested it without problem (i.e. it does change the strings) and then I included it in Workbook_Open, assuming the strings would be modified before they were executed. It seems that isn't the case. When the workbook opens, I get a dozen or so ugly messages telling me it can't resolve the old incorrect file references. It seems my new code then executes and changes the strings successfully, but too late to avoid the many errors.

    Is there somewhere else I can put this code?

  2. #2
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: How do I modify a QueryTable connection string before it executes?

    If the queries are set to refresh on open, then your Open code will be too late. You would need to turn that option off.
    Good luck.

  3. #3
    Registered User
    Join Date
    02-03-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: How do I modify a QueryTable connection string before it executes?

    Thanks so much for that. Sometimes I spend too much time searching for the complex answer when there's a simple one staring me in the face.

    Cheers... Jeff.

  4. #4
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: How do I modify a QueryTable connection string before it executes?

    My pleasure - please do not forget to mark the thread solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1