Skip to main content

VBA - IE automation in already opened webpage

Sub Manta()



For csk = 1 To 99

' Determine if a specific instance of IE is already open.
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(x).Document.Location
my_title = objShell.Windows(x).Document.Title
'You can use my_title of my_url, whichever you want
If my_url Like "https://www.manta.com" & "*" Then 'identify the existing web page
Set IE = objShell.Windows(x)
Exit For
Else
End If
Next
Set objCollection = IE.Document.getElementsByTagName("h2")
'MsgBox (objCollection.Length)
i = 0
While i < objCollection.Length
rowValue = ThisWorkbook.Sheets("Data").UsedRange.Rows.Count + 1
ThisWorkbook.Sheets("Data").Cells(rowValue, 1).Value = objCollection(i).innertext
ThisWorkbook.Sheets("Data").Cells(rowValue, 2).Value = "https://www.manta.com" & objCollection(i).Children(0).getAttribute("href")
i = i + 1
Wend
Set objCollection = IE.Document.getelementsbyclassname("ng-binding")
i = 0
While i < objCollection.Length
If i = 3 Then
objCollection(i).Click
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
GoTo Line1
End If
i = i + 1
Wend
'ng-binding
Line1:

Application.Wait (Now + TimeValue("0:00:10"))


Next csk

End Sub

Comments

Popular posts from this blog

Python - PyQt5 set Background image

import sys from PyQt5.QtCore import QSize from PyQt5.QtGui import QImage, QPalette, QBrush from PyQt5.QtWidgets import * class MainWindow ( QWidget ): def __init__ ( self ): QWidget. __init__ ( self ) self .setGeometry( 100 , 100 , 300 , 200 ) oImage = QImage( "test.jpg" ) sImage = oImage.scaled(QSize( 300 , 200 )) # resize Image to widgets size palette = QPalette() palette.setBrush( 10 , QBrush(sImage)) # 10 = Windowrole self .setPalette(palette) self .show() if __name__ == "__main__" : app = QApplication(sys.argv) oMainwindow = MainWindow() sys.exit(app.exec_())

pymsgbox - python package for message box

#This tutorial for to get a confirmation from the user by promting window #Python package "pymsgbox" needs to be install before run this below code #To install "pymsgbox" package go to command prompt and type in "PIP3 INSTALL pymsgbox" import pymsgbox #Displays a message box with OK and Cancel buttons. Number and text of buttons can be customized. Returns the text of the button clicked on. replyV = pymsgbox.confirm( text = 'Please login your application and click on on okay' , title = 'Login Confirmation' , buttons =[ 'OK' , 'Cancel' ]) print (replyV) #Displays a simple message box with text and a single OK button. Returns the text of the button clicked on. replyV = pymsgbox.alert( text = '' , title = '' , button = 'OK' ) print (replyV) #Displays a message box with text input, and OK & Cancel buttons. Returns the text entered, or None if Cancel was clicked. replyV1 = pyms