VBScript How to Find and Display MSGBOX of tabel cell contents

BennyBB

New Member
Joined
Sep 6, 2013
Messages
33
I am looking VBScript example that does the following:
1. opens webpage in internet explorer.
2. For webpage with a table diplay, reads all rows and columns 0 & 1.
3. Displays a msgbox for each item in column 0 along with row #. (msgbox = cellvalue & " found on row " & row)

Thanks for your help!

BennyBB

Here is what I have so far for URL emetalshop.websites.com

Code:
'    Visual Basic Script (VBS)
'
'
'
Option Explicit


'    Declaration of variables
Dim ie

'    Declaration of subroutines
'    Sub WaitForLoad waits for webpage to finish loading
'    before proceeding with next line of code
Sub WaitForLoad
Do while ie.Busy
wscript.sleep 200
Loop
End Sub

'    Open windows Internet explorer and surf to website
set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "emetalshop.webstarts.com"
ie.Toolbar=0
ie.StatusBar=0
ie.Height=560
ie.Width=1000
ie.Top=0
ie.Left=0
ie.Resizable=0
Call WaitForLoad
ie.Visible = true

'  Add code below to display in a msgbox the contents of each cell in column 0 (first column) should loop for each row.

'
dim i
dim table
dim CellContent0()
dim CellContent1()
Set table = document.getelementbyid("table")
redim CellContent0(table.rows.length-1)
redim CellContent1(table.rows.length-1)
CellContent0(i) = table.rows(i).cells(0).innerText
CellContent1(i) = table.rows(i).cells(1).innerText
for i = 0 to table.rows.lenth-1
    cellcontent0(i) = table.rows(i).cells(0).innertext
    cellcontent1(i) = table.rows(i).cells(1).innertext

msgbox cellcontent0(i) & " " & cellcontent1(i)

next
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this:
Code:
Option Explicit

'    Declaration of variables
Dim ie

'    Declaration of subroutines
'    Sub WaitForLoad waits for webpage to finish loading
'    before proceeding with next line of code
Sub WaitForLoad
    Do while ie.Busy or ie.readystate <> 4
        wscript.sleep 200
    Loop
End Sub

'    Open windows Internet explorer and surf to website
set ie = CreateObject("InternetExplorer.Application")
With ie
    .Navigate "emetalshop.webstarts.com"
    .Toolbar=0
    .StatusBar=0
    .Height=560
    .Width=1000
    .Top=0
    .Left=0
    .Resizable=0
    WaitForLoad
    .Visible = true
end with

'  Add code below to display in a msgbox the contents of each cell in column 0 (first column) should loop for each row.

dim table, row
Set table = ie.document.getelementsbytagname("table")(0)
for each row in table.rows
    MsgBox "row " & row.rowIndex + 1 & " " & row.cells(0).innerText & " " & row.cells(1).innerText 
next
 
Upvote 0
Thanks! Works just fine.

One more question.

How could I click on the link "yahoo" without "a" tag name. Is there a way to click the link by using the table cell quordinates (select the link and click by what row and column in the table)?
 
Upvote 0
Try:
Code:
table.Rows(0).Cells(1).getelementsbytagname("A")(0).Click
Unless you have a VBScript editor/debugger, I suggest you use Excel VBA to develop the code and use early binding of the InternetExplorer object (set a reference to Microsoft Internet Controls) and HTMLDocument and related classes (set a reference to Microsoft HTML Object Library) and then port it to VBScript with a few minor changes.
 
Upvote 0
Thanks that worked!

I am a beginner VBScript and VBA programmer. I haven't found a good book on VBS for internet explorer that explains how to click certain links and work with tables. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,223,627
Messages
6,173,424
Members
452,515
Latest member
Alicedonald9

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top