new workbook with new Query
Hi,
I am working on a macro that I'd like to insert a query table into a new
workboook.
To get the code for the create query part, I used the macro recorder.
Workbooks.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=pma;UID=;;SERVER=pma;", Destination:=Range("A1"))
.CommandText = Array( _
"Select * from acct_dim")
.Name = "Query from pma"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Without doing anything I just ran the macro again to test it and it faults at
.Refresh BackgroundQuery:=False with
RunTime '1004' Application-defined or object-defined error
Any ideas what could be causing the problem?
Thanks!
|