With what VBA macro commands can I switch between sheets, in order to execute specific Workbook Connecton SQL commands?
What I have tried is, to select a sheet, write the sheet specific sql command store that command in the specific connection's SQL command and then refresh the workbook to get the result. The code executes only on the sheet that it originally was executed on, not the sheet I selected.
Sheets("Alex").Select
' The SQL command text
Dim comText As String
comText = ... // the SQL command text
' Changes the workbook's SQL command text to the text in the code above
With ActiveWorkbook.Connections("conCRM").ODBCConnection // conCRM - the name of the conection
.commandText = comText
End With
' Refreshes data from the database
ActiveWorkbook.Connections("conCRM").Refresh
The thing that, in my opinion, is wrong is that the last line in the code targets the whole workbook and not the specific sheet I need.