Solved

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

Posted on 2012-04-09
1
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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!
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

726 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