Check links to .xls file - 08-04-2012 , 10:40 AM
I have a routine to check linkage to back end of a database and relink to it on opening of the application. In new application I have a number of spreadsheets that I have to insure are linked and am not sure how to amend the following code to search for these files.
Private Function RefreshLinks(strFileName As String) As Boolean
' Refresh links to the supplied Spreadsheet. Return True if successful.
Dim dbs As Database
Dim tdf As TableDef
' Loop through all tables in the Spreadsheet.
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
' If the table has a connect string, it's a linked table.
If Len(tdf.Connect) > 0 Then
tdf.Connect = ";DATABASE=" & strFileName
Err = 0
On Error Resume Next
tdf.RefreshLink ' Relink the table.
If Err <> 0 Then
RefreshLinks = False
RefreshLinks = True ' Relinking complete.
Hopefully answer to this question will be strong clue in amending the relinking function as well.
Thanks for any input.