Solved

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

Posted on 2012-04-09
1
313 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
ID: 37825792
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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