I tryed to make a script to detect the IE window that is opened on Facebook and hit the Like button. Let's say I have 10 IE opened. Only one of them is on a page on Facebook. I want my script to detect that IE window, click this button:
IE.Document.getElementById("pagesHeaderLikeButton")
(The above button is the Like button)
and close that IE window.
I tryed to get that IE window by:
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
Set IE = wnd
Exit For
End If
Next
But this will only set my VBscript to the first opened IE and it will not find the Facebook window.
I tryed this:
Dim objInstances, item
Set objInstances = CreateObject("Shell.Application").windows
For Each item In objInstances
If Item.Name Like "*Internet*" And Item.document.URL Like "*facebook.com*" Then
IE.Document.getElementById("pagesHeaderLikeButton").Click
End If
Next
But I get "Sub or function not defined"
So to press the button will be like this:
Next code snippet could help:
Output example (with more
facebook.com
matches):The following code will search for open IE windows that have "facebook.com" in its URL and save them in a collection:
Then you can loop through the collection and do what you want with the IE items:
Hope this does what you wanted! ;)