I am getting an error message while trying to update one excel table from another excel table in a different (and closed) workbook. The error only appear when the source workbook is not in a .xls format.
You cannot edit this field because it resides in a linked Excel spreadsheet. The ability to edit data in a linked Excel spreadsheet has been disabled in this Access Release.
This is supposed to be an expected behavior when using Access.
- Why am I seeing this error as I'm not working with Access but only two Excel files, and with a more recent version than 2007 ?
- How does this feature improve security ?
- Is there a workaround in my case ? Other than using a temp table in my target workbook.
UPDATE : Code example
Sub GetFiles()
'Take !M sheet to create files and their informations
Dim Base As FichierSource
'----------------------------
'Create files object
'----------------------------
'Fichier Source
Base.Path = "C:\Users\Lichar\Documents\SQL TEST\Base.xlsx"
Base.SourceSheet = "Data"
Base.TargetSheet = "Base"
Base.Columns = "*"
Base.Filter = "WHERE [Base$].id = [Data$].id"
Base.Name = "Base.xlsx"
'---------------------------
'Launch queries
'---------------------------
With Base
Call UPDATEQUERY(.Path, .SourceSheet, .TargetSheet, .Columns, .Filter)
End With
End Sub
Sub UPDATEQUERY(SourcePath As String, SourceSheet As String, TargetSheet As String, _
Columns As String, Filter As String)
Dim Cn As ADODB.Connection
Dim QUERY_SQL As String
Dim CHAINE_HDR As String
Dim STRCONNECTION As String
CHAINE_HDR = "[Excel 12.0;Provider=Microsoft.ACE.OLEDB.12.0;Mode=5;Extended Properties='HDR=YES;'] "
Set Cn = New ADODB.Connection
QUERY_SQL = _
"UPDATE [" & TargetSheet & "$] INNER JOIN (SELECT * FROM [" & SourceSheet & "$] " & _
"IN '" & SourcePath & "' " & CHAINE_HDR & ") t2 " & _
"ON [" & TargetSheet & "$].id = t2.id " & _
"SET [" & TargetSheet & "$].ColA = t2.ColA "
STRCONNECTION = _
"Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" & _
"DriverId=790;" & _
"Dbq=" & ThisWorkbook.FullName & ";" & _
"DefaultDir=" & ThisWorkbook.FullName & ";ReadOnly=False;"
Cn.Open STRCONNECTION
Cn.Execute (QUERY_SQL)
'--- Fermeture connexion ---
Cn.Close
Set Cn = Nothing
End Sub
Thanks