I am attempting to weed out the activate sheet events from code. I use the QueryTables.Add to open a web page in Excel. It doesn't seem to work unless I first activate the worksheet and then use ActiveSheet instead of the sheet name. Is this the way it is supposed to be?
Example (works):
Example (doesn't work):
Example (doesn't work):
AMAS
Example (works):
Code:
Worksheets("Temp").Activate
' Import web query
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & MyWebPage _
, Destination:=Range("$A$1"))
Example (doesn't work):
Code:
' Import web query
With Worksheets("Temp").QueryTables.Add(Connection:= _
"URL;" & MyWebPage _
, Destination:=Range("$A$1"))
Example (doesn't work):
Code:
Worksheets("Temp").Activate
' Import web query
With Worksheets("Temp").QueryTables.Add(Connection:= _
"URL;" & MyWebPage _
, Destination:=Range("$A$1"))
AMAS