+ Reply to Thread
Results 1 to 5 of 5

Changing Data Source

  1. #1
    Registered User
    Join Date
    01-28-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    4

    Changing Data Source

    Hi,

    I have been searching for a long time and can not find anything on this forum or others that can help with my current issue.
    We have a PROD and TEST environment and we use System DSN for the ODBC's for this particular application.

    Now some users create Excel reports which connect to the System DSN.
    This then creates a Data Connection within the Excel file itself which has an embedded SQL statement but points to the PROD database. Within this it also has the username and password of the System DSN.
    The PROD and TEST database are on the same server.
    We have approx 100 Excel reports all pointing to PROD all in the same directory.

    Is there a way I can copy all the files and place then in the TEST environment (Done, easy part).
    Then change all the connection to point to the TEST environment easily without having to go into each one and make the change.

    Appreciate any help that can be supplied.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Changing Data Source

    The general rule is anything you can do by hand can be done in a macro repetitively. Easiest way to test is to turn on the macro recorder, let it record you doing the change you want manually to one of the files in your given folder.... record, open file, make changes, save/close file, turn off recorder.

    Do that and post the junk code it creates here and we'll look at turning that one-off into a looper for your entire folder.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-28-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Changing Data Source

    Hi,
    Thanks for the reply.
    The macro does not help at all.
    I just did that and it just places the new connection in there.

    I have to manually go in and change the AppPROD to AppUAT
    and the INFOPROD to INFOUAT

    This needs to be changed in the Data --> Connections --> Properties of the connection --> Definition Tab
    Then change both the:
    • Connection String
    • Command Text


    Hope this helps

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Changing Data Source

    Untested but it should be something like this:
    Please Login or Register  to view this content.
    Note: if you have more than one pivot table connected to the same ODBC connection (rather than OLEDB), this may not work.
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    01-28-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Changing Data Source

    Hi,
    That code worked but it created a new connection and renamed the old one to Connection1.
    The piviot table automatically changed to connected to the one it was connected to before (now being connection1)

    Also if this can be acheived, can I run one VBA macro to change all Excel file in a particular folder at the one time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Changing Source Data for a Chart
    By dnamertz in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-28-2012, 10:47 PM
  2. Changing Graph Data Source
    By just_some_guy in forum Excel General
    Replies: 3
    Last Post: 07-20-2011, 03:24 AM
  3. Changing the Source Data
    By randyrest in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-07-2007, 02:56 PM
  4. Changing Data Source
    By arsimpson in forum Excel General
    Replies: 0
    Last Post: 04-06-2005, 01:30 PM

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