Hi
Is it possible to create a loop that will go through a list of Connection Only PQs, adding them as tables?
If I record a single macro, of me manually doing this, it does work, which is unreal.
However I have a list of say 10 queries and I would like it to do it for me.
This is what I get from the first one that works:
Sub Macro7()
'
Sheets.Add After:=ActiveSheet
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Pensions;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Pensions]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.ListObject.DisplayName = "Pensions"
.Refresh BackgroundQuery:=False
End With
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
End Sub
So I think I need something like an array of the query names and then replace the Pensions ref in here with Array(i) but I can't quite nail it.
Any hints ?
Is it possible to create a loop that will go through a list of Connection Only PQs, adding them as tables?
If I record a single macro, of me manually doing this, it does work, which is unreal.
However I have a list of say 10 queries and I would like it to do it for me.
This is what I get from the first one that works:
Sub Macro7()
'
Sheets.Add After:=ActiveSheet
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Pensions;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Pensions]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.ListObject.DisplayName = "Pensions"
.Refresh BackgroundQuery:=False
End With
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
End Sub
So I think I need something like an array of the query names and then replace the Pensions ref in here with Array(i) but I can't quite nail it.
Any hints ?