pulsar777
09-30-2019, 01:16 AM
Hi, I'd like to run SQL command on table, like this:
Sub Query()
Dim connString As String
Dim SQL As String
connString = "ODBC;DBQ=C:\My Folder\Query Macro.xlsm;DefaultDir=C:\My Folder;Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DriverId=;FIL=excel 12.0;MaxBufferSize=2048;MaxScanRows=1;PageTimeout=5;ReadOnly=1;SafeTransact ions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
SQL = "SELECT Current Month, New Price FROM [latest data$]"
With Worksheets("output")
.QueryTables.Add connString, .Range("A1"), SQL
.Range("A1").QueryTable.Refresh
End With
End Sub
I'm not sure about connection string - I have Office 365. The Column Names contain spaces and so does the worksheet ("latest data")
Can you help me solve it ?
Sub Query()
Dim connString As String
Dim SQL As String
connString = "ODBC;DBQ=C:\My Folder\Query Macro.xlsm;DefaultDir=C:\My Folder;Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DriverId=;FIL=excel 12.0;MaxBufferSize=2048;MaxScanRows=1;PageTimeout=5;ReadOnly=1;SafeTransact ions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
SQL = "SELECT Current Month, New Price FROM [latest data$]"
With Worksheets("output")
.QueryTables.Add connString, .Range("A1"), SQL
.Range("A1").QueryTable.Refresh
End With
End Sub
I'm not sure about connection string - I have Office 365. The Column Names contain spaces and so does the worksheet ("latest data")
Can you help me solve it ?