Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Dynamic Web Query from VBA

Hi,

I'm trying to pull down information from a web site. I need to do it
multiple times with one of the parameters in the url changing each time. I
know it's possible but I can't seem to find the proper way to do this.

example:
http://finance.yahoo.com/q?s=aa

the s=aa would need to change to something like s=ge and then something like
s=pfe, etc.

Any help greatly appreciated.

Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Dynamic Web Query from VBA

Hi Mike,
this is a primitive code snippet that might help you on the way.
The assumption here is that a webquery already exists on your sheet.
Note that not all of the page is imported. You can figure out the selected
tables by recording the creation of your webquery with the macro recorder ...

Sub ChangeURL(sParam as String)

Dim qt As QueryTable

If ActiveSheet.QueryTables.Count 0 Then
Set qt = ActiveSheet.QueryTables(1)

With qt
.Connection = "URL;http://finance.yahoo.com/q?s=" & sParam
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebSelectionType = xlSpecifiedTables
' only certain tables are imported ...
.WebTables = "19,23,25"
.Refresh
End With

End If

End Sub

"ThisShouldBeEasy" wrote:

Hi,

I'm trying to pull down information from a web site. I need to do it
multiple times with one of the parameters in the url changing each time. I
know it's possible but I can't seem to find the proper way to do this.

example:
http://finance.yahoo.com/q?s=aa

the s=aa would need to change to something like s=ge and then something like
s=pfe, etc.

Any help greatly appreciated.

Mike

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Dynamic Web Query from VBA

On Sun, 22 May 2005 20:45:12 -0700, ThisShouldBeEasy wrote...

I'm trying to pull down information from a web site. I need to do it
multiple times with one of the parameters in the url changing each time. I
know it's possible but I can't seem to find the proper way to do this.


Put all the ticker symbols in column A, select them and run the macro.
I don't know all the proper Ticker Symbols, so perhaps you should lookup
these symbols and add them to the worksheet in column A.

*****************
Sub Get_Nyse_Data()
Dim C As Range
Dim strName As String
Dim strConnectString
Dim QT As QueryTable
On Error Resume Next

For Each C In Selection
strName = C.Value
strConnectString = _
"URL;http://finance.yahoo.com/q?s=" & C.Value
ThisWorkbook.Worksheets.Add
ActiveSheet.Name = strName

' On the Workspace worksheet,
'clear all existing query tables
For Each QT In ActiveSheet.QueryTables
QT.Delete
Next QT

' Define a new Web Query
Set QT = ActiveSheet.QueryTables.Add _
(Connection:=strConnectString, Destination:=Range("B1"))

With QT
.Name = strName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "23,25"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
End With

' Refresh the Query
QT.Refresh BackgroundQuery:=True

Next
End Sub
**************
I managed to find these symbols, but some don't appear to be correct.

MMM
AA
ALTR
AXP
AIG
AMGN
AMR
AOLS.OB
AMAT
T
BAC
ONE
BBY
BGEN
BA
BMY
BRCM
BRCD
CAT
CEPH
CHKP
CVX
CSCO
C
KO
DELL
DD
EK
EBAY
EMC
ELX
XOM
F
GE
GM
GENZ
GS
HAL
HPQ
HD
HON
IDPH
INTC
IBM
IP
INVN
JPM
JNJ
KLAC
KKD
MXIM
MCD
MRK
MER
MU
MSFT
MWD
MOT
NEM
NOK
NOC
NVLS
NVDA
ORCL
PEP
PFE
MO
PG
QLGC
QCOM
SNDK
SBC
SLB
SEBL
PCS
SBUX
SUNW
SYMC
TXN
TYC
UAL
UTX
VRTS
VZ
WMT
DIS
XLNX

--
Met vriendelijke groeten / Mit freundlichen Grüßen / With kind
regards/Avec mes meilleures salutations
BBert

April 20, 1986
Celtics (135) - Bulls (131)
Larry Bird: "God disguised as Michael Jordan"
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Dynamic Web Query from VBA

The following one worked for me. Try to modify it for your use.

Option Explicit

Sub Refresh()
Dim cl As Range, sht As Worksheet, rng As Range
Dim strName As String
Set rng = Worksheets("StockList").Range("B2:B200")
Application.ScreenUpdating = False
For Each cl In rng
If Trim(cl.Value) < "" Then
strName = cl.Value
Application.DisplayAlerts = False
On Error Resume Next
Set sht = Worksheets(strName)
sht.Delete
ThisWorkbook.Worksheets.Add
ActiveSheet.Name = strName
Application.DisplayAlerts = True
On Error GoTo 0
Sheets(strName).Activate
ActiveSheet.Range("A1") = strName

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://finance.yahoo.com/q?s=" & strName,
Destination:=Range("B1"))
.Name = "q?s=" & strName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "23,25"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
cl.Offset(0, 1) = ActiveSheet.Range("C1")
cl.Offset(0, 2) = ActiveSheet.Range("C3")
End If
Next cl
Application.ScreenUpdating = True
Worksheets("StockList").Activate
End Sub

===== * ===== * ===== * =====
Daniel CHEN


www.Geocities.com/UDQServices
Free Data Processing Add-in<

===== * ===== * ===== * =====

"BBert" wrote in message
e.nl...
On Sun, 22 May 2005 20:45:12 -0700, ThisShouldBeEasy wrote...

I'm trying to pull down information from a web site. I need to do it
multiple times with one of the parameters in the url changing each time.
I
know it's possible but I can't seem to find the proper way to do this.


Put all the ticker symbols in column A, select them and run the macro.
I don't know all the proper Ticker Symbols, so perhaps you should lookup
these symbols and add them to the worksheet in column A.

*****************
Sub Get_Nyse_Data()
Dim C As Range
Dim strName As String
Dim strConnectString
Dim QT As QueryTable
On Error Resume Next

For Each C In Selection
strName = C.Value
strConnectString = _
"URL;http://finance.yahoo.com/q?s=" & C.Value
ThisWorkbook.Worksheets.Add
ActiveSheet.Name = strName

' On the Workspace worksheet,
'clear all existing query tables
For Each QT In ActiveSheet.QueryTables
QT.Delete
Next QT

' Define a new Web Query
Set QT = ActiveSheet.QueryTables.Add _
(Connection:=strConnectString, Destination:=Range("B1"))

With QT
.Name = strName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingAll
.WebTables = "23,25"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
End With

' Refresh the Query
QT.Refresh BackgroundQuery:=True

Next
End Sub
**************
I managed to find these symbols, but some don't appear to be correct.

MMM
AA
ALTR
AXP
AIG
AMGN
AMR
AOLS.OB
AMAT
T
BAC
ONE
BBY
BGEN
BA
BMY
BRCM
BRCD
CAT
CEPH
CHKP
CVX
CSCO
C
KO
DELL
DD
EK
EBAY
EMC
ELX
XOM
F
GE
GM
GENZ
GS
HAL
HPQ
HD
HON
IDPH
INTC
IBM
IP
INVN
JPM
JNJ
KLAC
KKD
MXIM
MCD
MRK
MER
MU
MSFT
MWD
MOT
NEM
NOK
NOC
NVLS
NVDA
ORCL
PEP
PFE
MO
PG
QLGC
QCOM
SNDK
SBC
SLB
SEBL
PCS
SBUX
SUNW
SYMC
TXN
TYC
UAL
UTX
VRTS
VZ
WMT
DIS
XLNX

--
Met vriendelijke groeten / Mit freundlichen Grüßen / With kind
regards/Avec mes meilleures salutations
BBert

April 20, 1986
Celtics (135) - Bulls (131)
Larry Bird: "God disguised as Michael Jordan"



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic web query in Excel 2003 Farhomer Excel Discussion (Misc queries) 0 October 3rd 06 10:53 PM
db query with dynamic criteria Stanley Excel Discussion (Misc queries) 1 January 19th 06 07:47 PM
Dynamic use of Access query Laurent M Excel Programming 1 January 24th 05 09:58 AM
Web Query and Dynamic web address joev7777 Excel Programming 0 October 15th 04 09:11 PM
Dynamic Web Query Amanda MMW Excel Programming 3 June 14th 04 07:24 PM


All times are GMT +1. The time now is 02:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"