What I am trying to achieve:
1. Run a script that opens an .aspx webpage
2. Do a loop & search for hyperlink page numbers on the webpage from 1 to n & click on each.
3. During the loop I want to do a 'ctrl a' then a 'ctrl c' of each page clicked
4. Before going to the next page, open an existing excel workbook with sheet numbers 1 to n
and paste the data from the webpage onto the respective Sheet# (e.g. Webpage 2 data pasted on Sheet2 of the workbook etc)
What I can achieve with my attempted coding script:
1. I can get the loop working to go through each page on the webpage & select & copy all the text before moving to next page
2. I can get the loop working to go through each page on the webpage & then each sheet in my workbook (as a test - while commenting out the code for copy paste)
What I cant achieve is:
Having the two running concurrently.
Please see my attached script; Apologies I cant reference the actual .aspx webpage (though any website with page numbers will work) for a real test
but I imagine the issue may seem clear to those & most of you that are more experienced with autoit than I.
#include <AutoItConstants.au3>
#include <IE.au3>
#include <Excel.au3>
$sURL = "<any website with page numbers at the base>"
;$sURL = "https://www.xxxxxx.com.au/xxx/quote-data.aspx"
$oIE = _IECreate($sURL, 0, 0, 0)
$HWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($HWND, "", @SW_MAXIMIZE)
_IEAction($oIE, "visible")
_IELoadWait($oIE)
;_Excel_Close($oApp)
ProcessClose("Excel.exe")
Local $oExcel = ObjCreate("Excel.Application")
$oExcel.visible=1
$oExcel.WorkBooks.Open("C:\TEST.xlsx") ;create workbook with same number of sheets as the pages in the abovee webpage
$oExcel.Sheets("Sheet1").Select
;CHECKS THE .ASPX WEBPAGE TO FIND A PAGE NUMBER HYPERLINK FROM 1 TO n & CLICKS ON IT
For $i = 1 to 4
Tooltip($i)
Local $sMyString = $i
Local $iNumberOfWorksheets = $oExcel.Worksheets.Count
Local $oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
Local $sLinkText = _IEPropertyGet($oLink, "innerText")
If StringInStr($sLinkText, $sMyString) Then
_IEAction($oLink, "click")
_IELoadWait($oIE)
;THIS PART OF THE CODE WORKS IF I EXCLUDE THE 'oExcel.Sheets("Sheet" & $i).Select' ON NEXT LINE
;~ WinActivate($hWnd)
;~ Send("^a")
;~ Sleep(1000)
;~ Send("^c")
;~ MouseClick($MOUSE_CLICK_LEFT, 0, 500, 0)
;THIS PART OF THE CODE WORKS IF I EXCLUDE THE ABOVE 5 LINES
Sleep(500)
$oExcel.Sheets("Sheet" & $i).Select
Sleep(2500)
;THIS PART OF THE CODE EXAPLINS WHAT IM TRYING TO DO BUT CANT TEST YET
;~ Send("^v")
;~ Sleep(2000)
ExitLoop
EndIf
Next
Next
If I try to run the code in full I get an error on this line................. $oExcel.Sheets("Sheet" & $i).Selectrun
Any assistance would be met with indebted gratitude.