ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Web Query: Obtaining source link from a cell in a macro (https://www.excelbanter.com/excel-programming/349809-web-query-obtaining-source-link-cell-macro.html)

tx12345[_4_]

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

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


--
tx12345
------------------------------------------------------------------------
tx12345's Profile: http://www.excelforum.com/member.php...o&userid=24776
View this thread: http://www.excelforum.com/showthread...hreadid=499085


Chip Pearson

Web Query: Obtaining source link from a cell in a macro
 
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"
wrote in message
...

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


--
tx12345
------------------------------------------------------------------------
tx12345's Profile:
http://www.excelforum.com/member.php...o&userid=24776
View this thread:
http://www.excelforum.com/showthread...hreadid=499085




tx12345[_5_]

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

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


--
tx12345
------------------------------------------------------------------------
tx12345's Profile: http://www.excelforum.com/member.php...o&userid=24776
View this thread: http://www.excelforum.com/showthread...hreadid=499085


Tom Ogilvy

Web Query: Obtaining source link from a cell in a macro
 
Both worked fine for me.

--
Regards,
Tom Ogilvy


"tx12345" wrote in
message ...

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


--
tx12345
------------------------------------------------------------------------
tx12345's Profile:

http://www.excelforum.com/member.php...o&userid=24776
View this thread: http://www.excelforum.com/showthread...hreadid=499085





All times are GMT +1. The time now is 08:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com