Web Query: Obtaining source link from a cell in a macro

T

tx12345

Hi

When I create a macro for a web query, the code looks like this:



With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.etc.com/mypage.htm" _ , Destination:=Range("C4"))


Simple enough, but this macro is only good for one web page. How can I
query another web page without changing the macro, where the new web
address come from a particular cell on the worksheet?

All ideas welcome
Thx
 
C

Chip Pearson

Try something like the following. It takes the address from cell
A1.

With ActiveSheet.QueryTables.Add(Connection:= _
Range("A1").Text _
, Destination:=Range("C4"))


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"tx12345" <[email protected]>
wrote in message
news:[email protected]...
 
T

tx12345

Thnks for the reply.

OK, here is something more specific, and I know this works:


Code:
--------------------

Sub getprice()

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://quote.barchart.com/quote.asp?sym=V4Y0", Destination:=Range("C1"))
.Name = "quote.asp?sym=V4Y0"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End Sub
Code:
--------------------


But when I revise the code to read from A1:


Code:
--------------------

Sub getprice()

With ActiveSheet.QueryTables.Add(Connection:= _
Range("A1").Text, Destination:=Range("C1"))
.Name = "quote.asp?sym=V4Y0"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End Sub

--------------------



with A1 containing:

URL;http://quote.barchart.com/quote.asp?sym=V4Y0

I get a debug error

any ideas?

Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top