|
-
March 9th, 2010, 10:00 AM
#1
Strange VBA code to access webpage
Hi,
My question is about the following code I came across. The code works fine.
Note that there is no dot between forms(0) and (i) in the if statement. As far as I know, in VBA there is always a dot between an object and its child object. Why no dot here?
Code:
For i = 0 To ie.Document.forms(0).Length - 1
If ie.Document.forms(0)(i).Type = "submit" Then
ie.Document.forms(0)(i).Click
Exit For
End If
Next i
Thanks,
MG.
-
March 9th, 2010, 10:11 AM
#2
Re: Strange VBA code to access webpage
I'd say that that denotes an array with multiple dimensions, i.e a 2 dimesnional array :
http://www.cpearson.com/excel/VBAArrays.htm
-
March 9th, 2010, 02:19 PM
#3
Re: Strange VBA code to access webpage
HanneSThEGreaT,
Thanks for that. However, in the code there was no array defined. The code is trying to manipulate objects of a webpage which are not in array format.
MG.
-
March 9th, 2010, 03:01 PM
#4
Re: Strange VBA code to access webpage
Hannes is correct...it is an array...but not how you would think. It is a multidimensional array of HTML elements.
ie.Document.forms returns an array of all form elements within the page. So, ie.Document.forms(0) references the first form. ie.Document.forms(0)(i) is looping through each of the child elements of the form. If that element is a submit button (type="submit"), then it performs a mouse click on that element.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 9th, 2010, 03:51 PM
#5
Re: Strange VBA code to access webpage
PeejAvery,
Thanks. Is the form only object that shows its elements in array form?
MG.
-
March 10th, 2010, 01:11 AM
#6
Re: Strange VBA code to access webpage
Not necessarily, but in this case yes.
Remember, the Document Object Model is bascially what you should look up.
The document is the webpage itself, and it hosts an array of controls, for example, if you have a web page with 3 tables on it, that will be an array of tables and so on
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|