Re-linking an Excel File as a Table

K

Keith Wilby

Is it possible to adapt this function to re-link to an Excel spreadsheet?
I'm sure it must be but I'm not sure of the syntax.

Many thanks.

Keith.

Function faq_ConnectLink(strTable As String, strSourceDB As String)
' This function can be run by any user who has OpenRun permission
' on the source database. It works equally well to link tables
' from scratch or to relink previously attached tables. In-line
' error handling is used to ignore any errors
' Parameters:
' strTable
' Name of the table to be linked
' strSourceDB
' Fully-qualified path and filename of the source db
'
On Error Resume Next

Dim db As Database
Dim tdf As TableDef


Set db = CurrentDb()

' Delete the link if it already exists
db.TableDefs.Delete strTable

' Create new link
Set tdf = db.CreateTableDef(strTable)

' Set the properties of the new link
' and append to the tabledefs collection
tdf.SourceTableName = strTable
tdf.Connect = ";DATABASE=" & strSourceDB
db.TableDefs.Append tdf

End Function
 
K

Keith Wilby

Keith Wilby said:
Is it possible to adapt this function to re-link to an Excel spreadsheet?
I'm sure it must be but I'm not sure of the syntax.

Figured it out if anyone's interested.

' Set the properties of the new link
' and append to the tabledefs collection

tdf.SourceTableName = strTable & "$"
tdf.Connect = "Excel 8.0;DATABASE=" & strSourceDB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top