Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referring to the InternetExplorer Object containing body text

Status
Not open for further replies.

Rich5477

Technical User
May 7, 2001
2
0
0
US
Using VBA and interacting with MSIE, how do I refer to the InternetExplorer object which contains the body text of a typical web page (in order to select, copy, and paste the text into Excel)? This is what I have so far (all am I able to do is navigate to the URL):

Dim xxxxxx As Object
Set xxxxxx = CreateObject("InternetExplorer.Application")
With xxxxxx
.navigate (" .Visible = True
'??? Refer to InternetExplorer object containing body text'
'??? copy text ???
End With
'Paste page text contents into Excel'
End Sub
 
Not the best way to do it but if you can't find another way try this.

Private Sub CopyPage()
Dim xxxxxx As Object
Set xxxxxx = CreateObject("InternetExplorer.Application")
With xxxxxx
.navigate (" .Visible = True
Interaction.SendKeys "^A", Wait
Interaction.SendKeys "^C", Wait
End With
ActiveSheet.Paste
End Sub
 
Pretty slick and when I do manually works like a charm... eh... but for some reason the sendkeys method doesn't seem to work for me?

just for reference the code does actually bring up the tek-tip browser window but I don't seem to be getting the Ctl A and Ctl C keystrokes after the window has opened.

Suggestions?
I always makes things much harder than they should be... that way later I can slap myself in the forhead after spending hours and hours on two lines of code and say to myself "DUH!"
 
here is a start for you...
[tt]
Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xxxxxx As Object, I As Double, S As String
Set xxxxxx = CreateObject("InternetExplorer.Application")
With xxxxxx
.navigate " .Visible = True
End With

'this value can be changed based upon your internet connection
For I = 0 To 10000
DoEvents
Sleep 1
DoEvents
Next I

S = xxxxxx.document.body.innertext

Debug.Print S

'ActiveSheet.Paste

End Sub
[/tt]

Good Luck
 
Hi,

Instead of using the API to pause the connection you can use the inherent properties of the IEbrowser.

Use

Do While xxxxxx.ReadyState < READYSTATE_COMPLETE
NewHour = Hour(Now())
NewMinute = Minute(Now())
NewSecond = Second(Now()) + 1
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)
Application.Wait WaitTime
Loop

Matt Smith

No two nulls are the same
 

Very good MattSmithProg, but it was just a start, and here is a hint for Rich5477...All the pause is doing is waiting for the document to load completly.

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top