Results 1 to 4 of 4

Thread: Change Connection String in multiple workbooks (vba)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Itasca, IL USA
    Posts
    279

    Change Connection String in multiple workbooks (vba)

    Hello,

    I have many Excel workbooks that have a connection to a cloud based SQL server database. The IP address has since changed and I need to go into all of the workbooks and change the connection.

    My question is: Going forward, is there a way to store the connection information in one spot so I don't have to go into all workbooks to change the connection information? I wasn't sure what the best practice for this was... any advice is welcome.

    Thank you!
    Chrissy

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,440

    Re: Change Connection String in multiple workbooks (vba)

    Depends.

    Are you the only user accessing this Server from those Workbooks?
    If yes, you could store the connection in the Registry, or even more simple: a textfile on your computer (filename/location should not be changed!)

    If there are other users accessing this server with this connection, then a textfile in a central spot (file-server?) would be easiest (see above for filename/location)

    In any case it would just be a simple read-instruction in Workbook_Open
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Itasca, IL USA
    Posts
    279

    Re: Change Connection String in multiple workbooks (vba)

    There are multiple users.

    Thank you for your reply. I wasn't sure if there was a better way. I tried searching and someone mentioned an add-in, but I don't think that is what I need.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Change Connection String in multiple workbooks (vba)

    someone mentioned an add-in,
    there may be some addin to look in every opened workbook for the connection string then edit it, but i would go with some external storage of the ip address, as suggested above, if the multiple users are not in a single location (LAN), then the file could be on some fixed server (as long as it's address can't change)

    edit
    for an initial instance, to change from a static internal string to a external file source,
    to update all workbooks (as they are opened) for a machine, it would be fairly easy to put code into the workbooks_open event of the personal workbook to search for the connection string and edit to use an external source, or you could write an addin to do the same so it could be distributed
    Last edited by westconn1; Jun 27th, 2018 at 04:16 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width