Advertisement
qharr

Untitled

Apr 19th, 2019
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Sub CopyWebTable()
  4.  
  5. Dim IE As InternetExplorer, hTable As Object, clipboard As Object, t As Date
  6. Dim Var As String
  7. Const MAX_WAIT_SEC As Long = 5
  8. Set clipboard = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  9. Set IE = New InternetExplorer
  10.  
  11. With IE
  12. .Visible = True
  13.  
  14. For i = 1 To 3
  15. Var = ThisWorkbook.Worksheets("Par").Range("B" & i + 2)
  16.  
  17. .Navigate2 "https://eresearch.fidelity.com/eresearch/evaluate/fundamentals/earnings.jhtml?tab=details&symbols=" & Var
  18.  
  19. While .Busy Or .readyState < 4: DoEvents: Wend
  20.  
  21. t = Timer 'timed loop for details table to be present
  22. Do
  23. On Error Resume Next
  24. Set hTable = IE.document.querySelector(".earningsHistoryTable-Cont table")
  25. On Error GoTo 0
  26. If Timer - t > MAX_WAIT_SEC Then Exit Do
  27. Loop While hTable Is Nothing
  28. If Not hTable Is Nothing Then 'use clipboard to copy paste
  29. clipboard.SetText hTable.outerHTML
  30. clipboard.PutInClipboard
  31. ThisWorkbook.Worksheets(Var).Range("A1").PasteSpecial
  32. Set hTable = Nothing
  33. End If
  34. Next i
  35. End With
  36. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement