jm.andryszak
XLDnaute Occasionnel
Bonjour
Cette macro fonctionne si Tableau_1 est un tableau "standard"
mais s'il est déclaré Listobjects, elle ne fonctionne plus
Comment puis-je résoudre ce problème ?
En vous remerciant
Sub Test()
'***********************************************
Dim SQL
Dim Source
Dim DefaultDir 'Optionnel
Dim Tbl As listobject
'***********************************************
Application.ScreenUpdating = False
On Error Resume Next
Set Tbl = ActiveSheet.ListObjects(1)
ActiveSheet.ListObjects(1).Delete
On Error GoTo 0
'
Source = ThisWorkbook.Path & "\Source_Query.xlsm"
DefaultDir = ThisWorkbook.Path
SQL = "SELECT Colonne1 FROM Tableau_1"
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
"ODBC;DSN=Excel Files;DBQ=" & Source & ";DefaultDir=" & DefaultDir & ";DriverId=1046;MaxBufferSize=200"), _
Array(";PageTimeout=5;")), Destination:=Range("$a$1")).QueryTable 'Array("48;PageTimeout=5;"))
.CommandText = SQL
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.listobject.DisplayName = "Resultat"
.Refresh BackgroundQuery:=False
End With
End Sub
'***********************************************
Cette macro fonctionne si Tableau_1 est un tableau "standard"
mais s'il est déclaré Listobjects, elle ne fonctionne plus
Comment puis-je résoudre ce problème ?
En vous remerciant
Sub Test()
'***********************************************
Dim SQL
Dim Source
Dim DefaultDir 'Optionnel
Dim Tbl As listobject
'***********************************************
Application.ScreenUpdating = False
On Error Resume Next
Set Tbl = ActiveSheet.ListObjects(1)
ActiveSheet.ListObjects(1).Delete
On Error GoTo 0
'
Source = ThisWorkbook.Path & "\Source_Query.xlsm"
DefaultDir = ThisWorkbook.Path
SQL = "SELECT Colonne1 FROM Tableau_1"
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
"ODBC;DSN=Excel Files;DBQ=" & Source & ";DefaultDir=" & DefaultDir & ";DriverId=1046;MaxBufferSize=200"), _
Array(";PageTimeout=5;")), Destination:=Range("$a$1")).QueryTable 'Array("48;PageTimeout=5;"))
.CommandText = SQL
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.listobject.DisplayName = "Resultat"
.Refresh BackgroundQuery:=False
End With
End Sub
'***********************************************