Results 1 to 16 of 16

Thread: [RESOLVED] Getting Web Page data into Excel

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Resolved [RESOLVED] Getting Web Page data into Excel

    I'm using the code below to go to a web page, copy all of the data and paste to clipboard. The web page, when first opened, has its focus set on a field that is expecting user input. So, when I paste what's in the clipboard into Excel, I get "Enter a name or symbol", which is the field's solicitation. How can I skip, unfocus, or otherwise get around this solicitation, so that when I 'copy all' I in fact get the entire web page and not the field solicitation? Thanks.

    HTML Code:
        Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = True
            .Navigate (url)
            Do Until .ReadyState = 4: DoEvents: Loop
            .ExecWB 17, 0 '// SelectAll
            .ExecWB 12, 2 '// Copy selection
            .Quit           
        End With    
        ActiveSheet.Paste

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Getting Web Page data into Excel

    I think you would rather use a more solid technique.

    Check out Get External Data > From Web

    What version of Excel are you using?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Getting Web Page data into Excel

    2007. Thanks.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Getting Web Page data into Excel

    Did you check out the get external data? Its in the Data tab
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Getting Web Page data into Excel

    When I use the 'Get External Data from Web' method (which I would then record as a macro because I'll be looping throough several web retrievals), I get only text data. I need to gain access to the hyperlinks that are on the web page. Thanks.

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Getting Web Page data into Excel

    @ROB: AH!!! Look who is here Long time

    @doasidont: You can use .InnerHTML to get the text Contents of the webpage
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Getting Web Page data into Excel

    Here is an example

    Code:
    Option Explicit
    
    Sub Sample()
        Dim IE As Object
        
        Set IE = CreateObject("InternetExplorer.Application")
        
        With IE
            .Visible = True
            .Navigate "Google.Com"
            Do Until .ReadyState = 4: DoEvents: Loop
            
            Range("A1").Value = IE.Document.documentElement.innerhtml
            .Quit
        End With
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Getting Web Page data into Excel

    Thanks, but that does not seem to be working. All I get is a lot of text data in "A1", but no hyperlinks that are down further on the web page.

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Getting Web Page data into Excel

    Can you share the URL with us?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Getting Web Page data into Excel

    This is my starting url: http://www.nasd100.com/2012/01/stron...an-9-2012.html

    On the web page that's retrieved, I'm trying to capture the urls that go with 'Balance Sheet' and 'Income Statement'. I'll use these urls to load up Excel with the repective data. Balance Sheet url is: http://moneycentral.msn.com/investor...tr&symbol=ANAC

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Getting Web Page data into Excel


  12. #12
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Getting Web Page data into Excel

    >>>On the web page that's retrieved, I'm trying to capture the urls that go with 'Balance Sheet' and 'Income Statement'.

    I have opened that page but I am unable to locate that link. Where exactly is that link?

    Edit: Ok. Looking at the new URL now.
    Last edited by Siddharth Rout; Jan 17th, 2012 at 02:14 PM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  13. #13
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Getting Web Page data into Excel

    within body line 341+ after <spn>finacials</span>

    nothing particularly unique about this part of page

    her to help if help is needed

  14. #14
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Getting Web Page data into Excel

    Ok the code is ready. Do you specifically want the URL OF 'Balance Sheet' and 'Income Statement' or just the innerHTML?

    EDIT

    Here is the code to get just the URL's

    Code:
    Option Explicit
    
    Sub Sample()
        Dim MyArray1() As String, MyArray2() As String, TempARR() As String
        Dim InComeURL As String, BalanceURL As String
        Dim IE As Object
        Dim i As Long
        Dim tbl
        
        Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = True
            .Navigate "http://investing.money.msn.com/investments/stock-price?symbol=ANAC&"
            Do Until .ReadyState = 4: DoEvents: Loop
            
            Set tbl = .Document.getElementById("LeftNav")
            
            MyArray1 = Split(tbl.innerHTML, vbCrLf)
            
            For i = 0 To UBound(MyArray1)
                If InStr(1, MyArray1(i), "Income Statement") Then
                    TempARR = Split(MyArray1(i), "><A href=""")
                    MyArray2 = Split(TempARR(1), """>")
                    InComeURL = MyArray2(0)
                End If
                
                If InStr(1, MyArray1(i), "Balance Sheet") Then
                    TempARR = Split(MyArray1(i), "><A href=""")
                    MyArray2 = Split(TempARR(1), """>")
                    BalanceURL = MyArray2(0)
                End If
            Next i
        End With
        
        MsgBox "Income Statement URL is : " & vbCrLf & InComeURL _
        & vbCrLf & vbCrLf & _
        "Balance Sheet URL is : " & vbCrLf & BalanceURL
        
        IE.Quit
        
        Set IE = Nothing
    End Sub
    Last edited by Siddharth Rout; Jan 17th, 2012 at 02:56 PM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: Getting Web Page data into Excel

    Very nice. Thanks to all of you.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    382

    Re: [RESOLVED] Getting Web Page data into Excel

    The code you gave works and I'm really appreciative of it, but there seems to be a little glitch in the Balance Sheet url that causes it not to work. "AMP;" occurs twice and it is not in the Properties url of the Balance Sheet hyperlink. No big deal as I can remove these characters with code, but if there's a simple change to your code that would fix it, that would be great. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width