Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Modifying ODBC data source for multiple reports

Hello all

My company is moving the business system from one server to another
one so we need to change the ODBC data source for all the reports. The
reports were created using MS Excel 2003. My task is to change every
single report (there are a lot of reports). Right now what I am doing
is manually changing the ODBC by opening the report and
ToolsMacrosMS Script Editor then I find the DNS=name of ODBC driver;
DB=name of DB, etc. This is taking me forever for each report since
there are multiple worksheet in each excel report file.

My question: Is there any way I can create a script to automatically
change the ODBC data source from the old server to the new server? or
maybe another faster way to do this?

Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Modifying ODBC data source for multiple reports

Like many others thing in Excel there is a object for ODBC data
connection. The object is the QueryTable. With this object you can
change many properties of the ODBC connection. Look this example:

Sub ChangeODBCString()
Dim qt As Excel.QueryTable


For Each qt In Sheets(1).QueryTables
qt.Connection =
"ODBC;DSN=ODBCName;pwd=PASSWORD;UID=UserId;;DBQ=Da tabaseName;"
Next qt

End Sub

You can make loops for every book open, every sheet in the book, every
QueryTable in the sheet...

Good Luck

Marco Barboza - San José, Costa Rica

On Feb 5, 12:02 pm, "erick-flores" wrote:
Hello all

My company is moving the business system from one server to another
one so we need to change the ODBC data source for all the reports. The
reports were created using MS Excel 2003. My task is to change every
single report (there are a lot of reports). Right now what I am doing
is manually changing the ODBC by opening the report and
ToolsMacrosMS Script Editor then I find the DNS=name of ODBC driver;
DB=name of DB, etc. This is taking me forever for each report since
there are multiple worksheet in each excel report file.

My question: Is there any way I can create a script to automatically
change the ODBC data source from the old server to the new server? or
maybe another faster way to do this?

Thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Modifying ODBC data source for multiple reports

Thanks for ur reply.

Can you give me more details, where do I put this code?

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Modifying ODBC data source for multiple reports

I do have multiple worksheet, where do i need to put this code in the
differente worksheets?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Modifying ODBC data source for multiple reports

Always is better to insert a new module and that module create a new
process. In my work I had the same problem as you, so I made this
litlle script:

Public Sub FixConnectionString()

Dim objWorkbook As Excel.Workbook
Dim objWorkSheet As Excel.Worksheet
Dim MyQuery As Excel.QueryTable
Dim Cont As Byte
Cont = 0
For Each objWorkbook In Application.Workbooks
For Each objWorkSheet In objWorkbook.Worksheets
For Each MyQuery In objWorkSheet.QueryTables
MyQuery.Connection = "ODBC;" 'Here comes the new connection
string that works for you
Cont = Cont + 1
Next MyQuery
Next objWorkSheet
Next objWorkbook
MsgBox "Queries OK:" & Cont , vbInformation + vbOKOnly, "END OF
PROCESS"

End Sub

Good Luck!

On Feb 6, 11:25 am, "erick-flores" wrote:
I do have multiple worksheet, where do i need to put this code in the
differente worksheets?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Modifying ODBC data source for multiple reports

Thank you very much, that worked perfect :D

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing data source on ODBC query Aussie CPA Excel Discussion (Misc queries) 2 June 14th 07 05:44 PM
how can i create quiries in excel from ODBC data source radhee Excel Programming 1 July 5th 06 03:34 PM
change odbc data source jenn Excel Worksheet Functions 0 January 20th 06 12:12 AM
Try again: VBA to automatically install ODBC data source Hall Excel Programming 4 April 23rd 04 10:25 AM
Retrieving data with SQL from ODBC source Clint[_2_] Excel Programming 1 April 12th 04 11:50 PM


All times are GMT +1. The time now is 02:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"