Solved

How to Extract String from Web Page and Assign that to Variable in VBA

Posted on 2012-04-09
1
306 Views
Last Modified: 2012-04-26
How to Extract String from Web Page and Assign that to Variable in VBA

Please share the piece of code
0
Comment
Question by:srikanth15
1 Comment
 
LVL 14

Accepted Solution

by:
sungenwang earned 500 total points
Comment Utility
Here is a piece of code that opened google, populates ID field, then save the ID field in variable 'str'.

Sub test()
    strURL = "https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Fnsr%3D1%26ui%3Dhtml%26zy%3Dl&ltmpl=default&ltmplcache=2"
    strLoginName = "abcdefg"
    intTimeOut = 10
    
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Visible = True
    objIE.Navigate2 strURL
    
    If Err Then
        MsgBox "Error with IE object!"
        WScript.Quit
    End If
    
    
    boolTimedOut = False
    Do While objIE.Busy
        Application.Wait DateAdd("s", 10, Now)
        i = i + 1
        If i > CInt(intTimeOut * 10) Then
            boolTimedOut = True
            MsgBox "Timeout expired waiting for IE object to stop loading!"
            Exit Sub
        End If
    Loop
    
    objIE.document.getElementById("Email").Value = strLoginName
    
    Dim str As String
    str = objIE.document.getElementById("Email").Value
    
    MsgBox "str = [" & str & "]"
    
    'objIE.document.getElementById("signIn").Click
    'objIE.Quit
End Sub

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now