Data Connection

Abvlecxe

Board Regular
Joined
Sep 10, 2015
Messages
53
Hi,
I have two excel files, worksheet1 is linked to worksheet2 via a data connection query to retrieve table information.

Everything works fine when the files are in the same location, however when I send the files to someone else on a different server the connection falls over. Other than guide the user through changing the data connection file path what alternative solutions is there so there is as little user requirement as possible?

I thought of potentially a macro button which when pressed asked for the new connection file path, the user types that into the input box and the macro updates the connection, is this possible? Or are there better solutions?

Thanks in advance
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
the connection should not use Drive letters, instead have full UNC paths: \\server\folder\file

the user must have access rights to the location \\server\folders
 
Upvote 0

I have come across this code which requires the user toselect a new source file, however when selected the query connections don’tactually update.

Any ideas?


Sub xlTest()

Dim i As Long

Dim cnt As Long

Dim cn


cnt = ActiveWorkbook.Connections.Count


'Choose a File

strPath = Application.GetOpenFilename(Title:="Choosea file", _

FileFilter:="Excel Files *.xls* (*.xls*),")

If strPath = False Then

MsgBox "Nofile selected. Exiting now.", vbExclamation


Exit Sub

End If

'Change Connection source filepath for each connection

For i = cnt To 1 Step -1

Set cn =ActiveWorkbook.Connections.Item(i)

cn.OLEDBConnection.SourceDataFile = strPath

Next i


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,681
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top