Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ardus Petus
 
Posts: n/a
Default Change database in Excel

Ooops:
Dim qt as Querytable
set qt=Activesheet.Querytables(1)
....


"Ardus Petus" a écrit dans le message de news:...
dim qt=Activesheet.querytables(1)
qt.connection = blah
qt.sql = blah

HTH
--
AP

"Catarina" a écrit dans le message de
...
Hi.
I have two databases that are similar, and i have created an Excel

document
that imports data from one database.
My problem is that i want to change the database of the document
programatically. I think that creating a macro in VBA the problem is

solved.
But i don't know how to do it.
Anyone have any idea?
Thanks
Catarina





  #2   Report Post  
Posted to microsoft.public.excel.misc
Catarina
 
Posts: n/a
Default Change database in Excel


Thanks for your help.
But this script only makes me choose another ODBC connection, it doesn't
change my database.
Is like this, i choose another ODBC connection with another database but it
uses the old database.
I don't understand why.
If you know something else that could help i apreciated.
Thank you, anyway.

"Ardus Petus" wrote:

Ooops:
Dim qt as Querytable
set qt=Activesheet.Querytables(1)
....


"Ardus Petus" a écrit dans le message de news:...
dim qt=Activesheet.querytables(1)
qt.connection = blah
qt.sql = blah

HTH
--
AP

"Catarina" a écrit dans le message de
...
Hi.
I have two databases that are similar, and i have created an Excel

document
that imports data from one database.
My problem is that i want to change the database of the document
programatically. I think that creating a macro in VBA the problem is

solved.
But i don't know how to do it.
Anyone have any idea?
Thanks
Catarina






  #3   Report Post  
Posted to microsoft.public.excel.misc
Ardus Petus
 
Posts: n/a
Default Change database in Excel

If your database is an Access mdb:

Sub ModQuery()
Const oldpath = "U:\Databases\mydatabase"
Const newpath = "C:\mydatabase"
Dim qt As QueryTable
Set qt = ActiveSheet.QueryTables(1)
With qt
.Connection = Replace(.Connection, oldpath, newpath)
.CommandText = Replace(.CommandText, oldpath, newpath)
End With
End Sub

HTH,
--
AP

"Catarina" a écrit dans le message de
...

Thanks for your help.
But this script only makes me choose another ODBC connection, it doesn't
change my database.
Is like this, i choose another ODBC connection with another database but

it
uses the old database.
I don't understand why.
If you know something else that could help i apreciated.
Thank you, anyway.

"Ardus Petus" wrote:

Ooops:
Dim qt as Querytable
set qt=Activesheet.Querytables(1)
....


"Ardus Petus" a écrit dans le message de

news:...
dim qt=Activesheet.querytables(1)
qt.connection = blah
qt.sql = blah

HTH
--
AP

"Catarina" a écrit dans le

message de
...
Hi.
I have two databases that are similar, and i have created an Excel
document
that imports data from one database.
My problem is that i want to change the database of the document
programatically. I think that creating a macro in VBA the problem is
solved.
But i don't know how to do it.
Anyone have any idea?
Thanks
Catarina







  #4   Report Post  
Posted to microsoft.public.excel.misc
Catarina
 
Posts: n/a
Default Change database in Excel


Thank you, for this script.
My database is an SQL Server file, but i'll try to adapt the script.


"Ardus Petus" wrote:

If your database is an Access mdb:

Sub ModQuery()
Const oldpath = "U:\Databases\mydatabase"
Const newpath = "C:\mydatabase"
Dim qt As QueryTable
Set qt = ActiveSheet.QueryTables(1)
With qt
.Connection = Replace(.Connection, oldpath, newpath)
.CommandText = Replace(.CommandText, oldpath, newpath)
End With
End Sub

HTH,
--
AP

"Catarina" a écrit dans le message de
...

Thanks for your help.
But this script only makes me choose another ODBC connection, it doesn't
change my database.
Is like this, i choose another ODBC connection with another database but

it
uses the old database.
I don't understand why.
If you know something else that could help i apreciated.
Thank you, anyway.

"Ardus Petus" wrote:

Ooops:
Dim qt as Querytable
set qt=Activesheet.Querytables(1)
....


"Ardus Petus" a écrit dans le message de

news:...
dim qt=Activesheet.querytables(1)
qt.connection = blah
qt.sql = blah

HTH
--
AP

"Catarina" a écrit dans le

message de
...
Hi.
I have two databases that are similar, and i have created an Excel
document
that imports data from one database.
My problem is that i want to change the database of the document
programatically. I think that creating a macro in VBA the problem is
solved.
But i don't know how to do it.
Anyone have any idea?
Thanks
Catarina








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
How to change the color of all series in an excel chart in one go. Marielle Charts and Charting in Excel 2 May 3rd 23 07:45 PM
Excel 2002 Add-in: Open Database Connectivity available for Excel Nick B Excel Discussion (Misc queries) 8 December 7th 06 06:04 PM
Database and Excel Fable Excel Discussion (Misc queries) 0 January 20th 06 09:26 PM
Force format change in excel Benson Excel Worksheet Functions 5 November 29th 05 10:41 AM
Open Access Database under and Excel window using a Macro BMSpell Excel Worksheet Functions 1 January 8th 05 05:32 PM


All times are GMT +1. The time now is 09:25 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"