我尝试从另一个(和已关闭的)工作簿中的另一个Excel表更新一个Excel表时收到错误消息。 仅当源工作簿不是.xls格式时才会出现错误。
您无法编辑此字段,因为它位于链接的Excel电子表格中。在此Access Release中已禁用在链接的Excel电子表格中编辑数据的功能。
使用Access时,这应该是expected behavior。
更新:代码示例
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
由于
答案 0 :(得分:1)
这三个问题合而为一,但我会尝试回答所有这些问题: