我编写了一个宏,它从网站获取源数据并下载、复制和粘贴活动工作表中的每一行。当我从 Lines2(k - 1).Copy 移动到下一行时,我得到运行时错误 424 Object is required。
Private Sub UserForm_Click()
Dim URL2 As String: URL2 = "http://finance.yahoo.com/"
' to get data from the url we need to creat a win Http object_
' tools > references > select Windows Win Http Services 5.1
Dim Http2 As New WinHttpRequest
'open the url
Http2.Open "GET", URL2, False
'Debug.Print s
'Debug.Print URL
' send request
Http2.Send
MsgBox Http2.ResponseText
Debug.Print s
'Debug.Print Http2
Debug.Print URL2
Dim Resp As String: Resp = Http2.ResponseText
Dim Lines2 As Variant: Lines2 = Split(Resp, vbNewLine)
Debug.Print Lines2(0)
f = UBound(Lines2)
For k = 1 To f + 1
Lines2(k - 1).Copy
Range(10 + k, 1).Select
ActiveSheet.Paste
Next k
End Sub