Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
alexkr
 
Posts: n/a
Default External Links not working


I have a spreadsheet which is linked to an Access DB table. In MS Query,
I changed the drive mapping (eg G:\data\etc) to the server name (eg
\\server\drivename\data\etc) in SQL view.

However, when colleagues who are mapped to the drive under a different
letter try to refresh the spreadsheet, it still comes up with the
error: "Cannot locate G:\data\etc"

Does anyone know why? There are many users in a large multi-site
organisation, and to change everyones mappings would be very
time-consuming.


--
alexkr
  #2   Report Post  
Bill Manville
 
Posts: n/a
Default

Alexkr wrote:
Does anyone know why? There are many users in a large multi-site
organisation, and to change everyones mappings would be very
time-consuming.


The filename will appear in 2 places: in the SQL (annoyingly) and you
have dealt with that, and in the Connection property of the QueryTable.
A further complication is that long Connection strings and SQL strings
have to be split into arrays containing strings which do not exceed 255
characters in length.

Try this macro:

Sub ChangeQuerySources()
Dim stFrom As String
Dim stTo As String
Dim stConn As String
Dim QT As QueryTable
Dim WS As Worksheet
Dim V
' change all querytables from one directory to another
' and change the directory from stFrom to stTo
' These are for your case:
stFrom = "G:\data\"
stTo = "\\Server\Drivename\Data\"
For Each WS In ActiveWorkbook.Worksheets
For Each QT In WS.QueryTables
stConn = Flatten(QT.Connection)
stConn = Subst(stConn, stFrom, stTo)
QT.Connection = SplitToArray(stConn, 255)
QT.Sql = SplitToArray(Subst(Flatten(QT.Sql), stFrom, stTo), 255)
QT.Refresh BackgroundQuery:=False
Next
Next
End Sub

Function Flatten(V) As String
Dim I As Integer
If IsArray(V) Then
For I = LBound(V) To UBound(V)
Flatten = Flatten & V(I)
Next
Else
Flatten = V
End If
End Function

Function Subst(ByVal InString As String, stReplace As String, stWith As
String) As String
' replace any occurrence of stReplace in InString with stWith
Dim stResult As String
Dim iChar As String
iChar = InStr(LCase(InString), LCase(stReplace)) ' string compare is
case sensitive
Do While iChar 0
stResult = stResult & Left(InString, iChar - 1) & stWith
InString = Mid(InString, iChar + Len(stReplace))
iChar = InStr(LCase(InString), LCase(stReplace))
Loop
Subst = stResult & InString
End Function

Function SplitToArray(ST As String, Lump As Integer)
' break a long string up into an array with each element of size Lump
' don't bother if string is not longer than Lump
Dim A()
Dim I As Integer
If Len(ST) <= Lump Then
SplitToArray = ST
Else
ReDim A(1 To Len(ST) \ Lump + 1)
For I = 1 To Len(ST) \ Lump + 1
A(I) = Mid(ST, 1 + (I - 1) * Lump, Lump)
Next
SplitToArray = A()
End If
End Function





Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - respond to newsgroup

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
Update Automatic Links Not Working in 2003 cydkil Excel Discussion (Misc queries) 2 February 15th 05 03:35 PM
How do I remove external links from Excel 2000 workbook? mlwest Excel Discussion (Misc queries) 2 February 4th 05 10:52 PM
If I don't have children open I get #REF! where external links are Colettb Excel Discussion (Misc queries) 0 February 2nd 05 05:49 PM
Pivot tables, external data sources and ODBC links plato Excel Worksheet Functions 0 January 17th 05 05:07 PM
excel links update not working in auto, calculations in auto Mikey Boy Excel Worksheet Functions 0 December 7th 04 11:53 PM


All times are GMT +1. The time now is 01:23 PM.

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"