0

win 7 で Web から Excel ワークシートにデータをインポートしようとしています。

しかし、左の の部分の仕上げ方がわかりません。

Sub Ex2Macro()

    Ex2 from Macro1 Macro
    ' Macro changed 17/07/2007 by Dr. B. I. Czaczkes
    Dim qt As QueryTable
    Dim temp As Variant ' Double
    Set qt = ActiveSheet.QueryTables.Add(Connection:= _
      "URL;http://finance.yahoo.com/q?s=GBPUSD=X", Destination:=ActiveCell.Range("A1"))
    With qt
    .Name = "query1"
    .BackgroundQuery = False
    .SaveData = True
    .WebSelectionType = xlSpecifiedTables
    .WebFormatting = xlWebFormattingNone
    .WebTables = "14"
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .Refresh BackgroundQuery:=False
  End With
  With qt.ResultRange
    .ClearContents
    .Range("a1").Value = "USD/GBP"
    .Range("b1").Value = ?     ' here, what I should put so that the queried result             
                               ' is printed ? 
  End With
End Sub

交換結果を提供する別のコード。

Sub Ex3Macro()
  Dim qt As QueryTable
  ' Dim temp As Double
  Dim temp As Variant
  temp = ActiveCell.Value
  Set qt = Worksheets("temp").QueryTables.Add(Connection:= _
    "URL;http://finance.yahoo.com/currency/convert?amt=" & _
    temp & _
    "&from=USD&to=GBP&submit=Convert" _
    , Destination:=Worksheets("Temp").Range("a1"))
  With qt
    .Name = "query2"
    .BackgroundQuery = False
    .SaveData = True
    .WebSelectionType = xlSpecifiedTables
    .WebFormatting = xlWebFormattingNone
    .WebTables = "13"
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .Refresh BackgroundQuery:=False
  End With
  ActiveCell.Range("b1").Value = qt.ResultRange.Range("e3").Value
End Sub

ただし、結果は出力されません。

どんな助けでも大歓迎です。

4

1 に答える 1

0

Microsoft WinHTTP サービス、バージョン 5.1 リファレンスを選択してから、次を使用してみてください。

Sub HTTPTest()

Dim httpRequest As WinHttpRequest
Dim URL As String, strHTML As String

If httpRequest Is Nothing Then
    Set httpRequest = New WinHttp.WinHttpRequest
End If

URL = "http://finance.yahoo.com/q?s=GBPUSD=X"

httpRequest.Open "GET", URL, True
httpRequest.Send
httpRequest.WaitForResponse
strHTML = httpRequest.ResponseText
Set httpRequest = Nothing

'Parse strHTML now to get your value

End Sub
于 2013-02-18T16:32:58.857 に答える