Sharid
Well-known Member
- Joined
- Apr 22, 2007
- Messages
- 1,066
- Office Version
- 2016
- Platform
- Windows
Hi
Is there a way to run ONE code in two parts, so I split the code into two, I already have a code that I can use, with minor modification, I just don't know how to split it, so it recoganises that the second part of the code is part of the original code (First Part).
The user has to go online an logon to a website so. I need the following
The second part would be a sub procedure of the first code. I was going to use webBrowser1, but the site does not display correctly in it so I am sticking with IE.
This is the first half, the second is a For Each Loop,
Is there a way to run ONE code in two parts, so I split the code into two, I already have a code that I can use, with minor modification, I just don't know how to split it, so it recoganises that the second part of the code is part of the original code (First Part).
The user has to go online an logon to a website so. I need the following
- Command Button1 click = Open the url, user logs on to the site
- Command Button2 click = The second part of the code runs.
The second part would be a sub procedure of the first code. I was going to use webBrowser1, but the site does not display correctly in it so I am sticking with IE.
This is the first half, the second is a For Each Loop,
VBA Code:
Dim Html As HTMLDocument
Dim objIE As Object
Dim y As Integer 'integer variable we'll use as a counter
Dim result As String 'string variable that will hold our result link
Dim pageNumber As Long ' page no.
Dim nextPageElement As Object 'page element
Dim HtmlText As Variant ' for html data
Dim wsSheet As Worksheet ' WorkSheet
Dim wb As Workbook
Set wb = ThisWorkbook
Set wsSheet = wb.Sheets("Sheet3")
y = 2 ' Start on row 2
'+++++ Internet Explorer ++++++
Set objIE = New InternetExplorer 'initiating a new instance of Internet Explorer and asigning it to objIE
' With objIE ' added by me
objIE.Visible = True 'make IE browser visible
objIE.navigate Sheets("Sheet3").Range("A2").Value & Replace(Worksheets("Sheet3").Range("B2") & Range("C2").Value, " ", "+") 'navigate IE to this web page
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop 'wait here a few seconds while the browser is busy
Set ie = CreateObject("InternetExplorer.Application")
Set Html = objIE.document
Set elements = Html.getElementsByClassName("sresult lvresult clearfix li shic") ' parent CLASS
' From here on it is the FOR EACH LOOP in the code, which I took out and placed in the second command button.