Jump to content
Sign in to follow this  
XinYoung

Do...Until Excel sheet has no more data?

Recommended Posts

Why hello there! :D

I have a script reading an Excel sheet (currently only looking at A1), copying the data in that cell, and then searching for it in a Website's search tool. Then it does some stuff if it actually finds something.

After that, I need it to go back to the Excel sheet, write "yes" into column B if the search was good -- "no" if no results were found, then go down to A2 and do the whole thing all over again until column A has nothing left.

:frantics: I really suck at loops and have a hard time grasping how it works. Any help or guidance is really appreciated!

 

SearchCourse()

;~  Now that were logged in, navigate to the course search page.
Func SearchCourse()
    _IENavigate($oIE, $urlBBCourseSearch)

;~  Change the search criteria to "Course ID"
    _bbCourseSearchCategoryChange("Course ID")

;~  Open the selected Excel file
    Local $oAppl = _Excel_Open()
    Local $oWorkbook = _Excel_BookOpen($oAppl, $ChosenFileName, Default, Default, True)

;~ Copy whats in the first cell (A1)
    _Excel_RangeCopyPaste($oWorkbook.Worksheets(1), "A1")
    Global $WhatsCopied = ClipGet()

;~ Paste whats copied into the search text box and click submit
    Local $oForm = _IEGetObjByName($oIE, "courseManagerFormSearch")
    Local $oSearchString = _IEFormElementGetObjByName($oForm, "courseInfoSearchText")
    _IEFormElementSetValue($oSearchString, $WhatsCopied)
    _IEFormSubmit($oForm)

;~ Lets see what we got from the search
    Local $oBBTable = _IETableGetCollection($oIE, 2)
    Global $aBBTableData = _IETableWriteToArray($oBBTable)
    _ArrayDisplay($aBBTableData)

    DeleteCourseBegin()

EndFunc   ;==>SearchCourse

;~ OK, we logged in and we searched for a course. Lets delete it!
Func DeleteCourseBegin()
    $iSearchIndex = _ArraySearch($aBBTableData, "Course ID", 0, 0, 0, 1, 1, 0)
    
;~  If the course was not found, do this.
    If $iSearchIndex = -1 Then
        MsgBox(4096, "Search Error", "Item not found")
;~  Now go back to the Excel sheet and search for the next one....?

;~ If the course was found, begin the deletion process.
    Else
        MsgBox(4096, "Search Success", $aBBTableData[$iSearchIndex][0] & " = " & $aBBTableData[$iSearchIndex][1])
        DeleteCourseNow()
    EndIf
EndFunc   ;==>DeleteCourseBegin

;~ The course search was successful. Delete the course now.
Func DeleteCourseNow()
;~ Click the checkbox located beside the course that has been found.
    Local $CheckBox = _IEGetObjByName($oIE, "ckbox")
    _IEAction($CheckBox, "click")
    _IELoadWait($oIE)

;~ Click the Delete button.
    _IELinkGetCollection($oIE)
    Local $oLinks = _IELinkGetCollection($oIE)
    For $oLink In $oLinks
        If $oLink.href = "javascript:validateRemove();" Then
            _IEAction($oLink, "click")
            ExitLoop
        EndIf
    Next

;~  Click the "Delete course, including all of its files" radio button.
    Local $RadioButton = _IEGetObjById($oIE, "removeAllFiles_t")
    _IEAction($RadioButton, "click")
    _IELoadWait($oIE)

;~ Click the "Submit" button
    Local $Submit = _IEGetObjByName($oIE, "bottom_Submit")
    _IEAction($Submit, "click")
    _IELoadWait($oIE)

;~  Now go back to the Excel sheet and search for the next one....?

EndFunc   ;==>DeleteCourseNow

 

 

Edited by XinYoung
Fixed some comments in the code

Share this post


Link to post
Share on other sites

If you do this after you make your workbook object, you will get the size of the excel workbook (know what the last line of the excel file will be).

#include <array.au3>

$array = _Excel_RangeRead($oWorkbook)
$size = Ubound($array)

Give adding in a loop a try now that you know the size. If you are still struggling with it, let us know!

Edited by Davidowicza
Grammar

Share this post


Link to post
Share on other sites

@XinYoung You can do this easily with _Excel_RangeWrite. Something like this should get you started:

#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @DesktopDir & "\Test1.xlsx")
Local $oRange = _Excel_RangeRead($oWorkbook, Default, Default)

For $a = 1 To UBound($oRange)
    ;Do other Stuff
    _Excel_RangeWrite($oWorkbook, Default, "This is cell B" & $a, "B" & $a)
Next

_Excel_BookClose($oWorkbook)
_Excel_Close($oExcel)

If your columns have headers, you'll have to adjust by one.


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites

It would be faster to just grab all of A:A into an array and loop through the results and create a second array to hold the "Yes/No" here is an example untested:

#include <Array.au3>
#include <Excel.au3>
Global $sChosenFileName = "Filename.xlsx"
Global $aBBTableData
Global $oExcel = _Excel_Open()
Global $oWorkbook = _Excel_BookOpen($oExcel, $sChosenFileName)
;~ Get all used cells in column A:A
Global $aSearchItems = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"))
;~ Duplicate the $aSearchItems Array 
Global $aSearchResult = $aSearchItems
;~ Loop through $aSearchItems
;~ Since Excel_RangeRead returns a 0-based Array and since we only captured one column it is a 1 dimension array
;~ Loop through the array starting at 0 until the end of the array which is (Ubound($aSearchItems) - 1)
For $i = 0 To UBound($aSearchItems) - 1
    $aSearchResult[$i] = SearchCourse($aSearchItems[$i])
Next
_ArrayDisplay($aSearchItems, "Search Items")
_ArrayDisplay($aSearchResult, "Search Results")
;~ Paste the results back to Excel in column B1
_Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "B1")

Func SearchCourse($_sSearch)
    _IENavigate($oIE, $urlBBCourseSearch)

;~  Change the search criteria to "Course ID"
    _bbCourseSearchCategoryChange("Course ID")

;~ Paste whats copied into the search text box and click submit
    Local $oForm = _IEGetObjByName($oIE, "courseManagerFormSearch")
    Local $oSearchString = _IEFormElementGetObjByName($oForm, "courseInfoSearchText")
    _IEFormElementSetValue($oSearchString, $_sSearch)
    _IEFormSubmit($oForm)

;~ Lets see what we got from the search
    Local $oBBTable = _IETableGetCollection($oIE, 2)
    $aBBTableData = _IETableWriteToArray($oBBTable)
    _ArrayDisplay($aBBTableData)

    DeleteCourseBegin()

EndFunc   ;==>SearchCourse

;~ OK, we logged in and we searched for a course. Lets delete it!
Func DeleteCourseBegin()
    $iSearchIndex = _ArraySearch($aBBTableData, "Course ID", 0, 0, 0, 1, 1, 0)
    
;~  If the course was not found, do this.
    If $iSearchIndex = -1 Then
        MsgBox(4096, "Search Error", "Item not found")
        $sResult = "No"
;~  Now go back to the Excel sheet and search for the next one....?

;~ If the course was found, begin the deletion process.
    Else
        MsgBox(4096, "Search Success", $aBBTableData[$iSearchIndex][0] & " = " & $aBBTableData[$iSearchIndex][1])
        DeleteCourseNow()
        $sResult = "Yes"
    EndIf
    Return $sResult
EndFunc   ;==>DeleteCourseBegin

;~ The course search was successful. Delete the course now.
Func DeleteCourseNow()
;~ Click the checkbox located beside the course that has been found.
    Local $CheckBox = _IEGetObjByName($oIE, "ckbox")
    _IEAction($CheckBox, "click")
    _IELoadWait($oIE)

;~ Click the Delete button.
    _IELinkGetCollection($oIE)
    Local $oLinks = _IELinkGetCollection($oIE)
    For $oLink In $oLinks
        If $oLink.href = "javascript:validateRemove();" Then
            _IEAction($oLink, "click")
            ExitLoop
        EndIf
    Next

;~  Click the "Delete course, including all of its files" radio button.
    Local $RadioButton = _IEGetObjById($oIE, "removeAllFiles_t")
    _IEAction($RadioButton, "click")
    _IELoadWait($oIE)

;~ Click the "Submit" button
    Local $Submit = _IEGetObjByName($oIE, "bottom_Submit")
    _IEAction($Submit, "click")
    _IELoadWait($oIE)
;~  Now go back to the Excel sheet and search for the next one....?

EndFunc   ;==>DeleteCourseNow

 

Edited by Subz

Share this post


Link to post
Share on other sites

OK, I tried implementing it but I'm getting an error: SearchCourse() called by a previous line with 0 arg(s)

Because of the way I call upon the func...?

 

OpenExcel()

Func OpenExcel()
    Global $aBBTableData
    Global $oExcel = _Excel_Open()
    Global $oWorkbook = _Excel_BookOpen($oExcel, $ChosenFileName, Default, Default, True)
;~ Get all used cells in column A:A
    Global $aSearchItems = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"))
;~ Duplicate the $aSearchItems Array
    Global $aSearchResult = $aSearchItems
;~ Loop through $aSearchItems
;~ Since Excel_RangeRead returns a 0-based Array and since we only captured one column it is a 1 dimension array
;~ Loop through the array starting at 0 until the end of the array which is (Ubound($aSearchItems) - 1)
    For $i = 0 To UBound($aSearchItems) - 1
        $aSearchResult[$i] = SearchCourse($aSearchItems[$i])
    Next
    _ArrayDisplay($aSearchItems, "Search Items")
    _ArrayDisplay($aSearchResult, "Search Results")
;~ Paste the results back to Excel in column B1
    _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "B1")

    SearchCourse()

EndFunc   ;==>OpenExcel


;~  Now that were logged in, navigate to the course search page.
Func SearchCourse($aSearchResult)
    _IENavigate($oIE, $urlBBCourseSearch)

    ;~  Change the search criteria to "Course ID"
    _bbCourseSearchCategoryChange("Course ID")

;~ Paste whats copied into the search text box and click submit
    Local $oForm = _IEGetObjByName($oIE, "courseManagerFormSearch")
    Local $oSearchString = _IEFormElementGetObjByName($oForm, "courseInfoSearchText")
    _IEFormElementSetValue($oSearchString, $aSearchResult)
    _IEFormSubmit($oForm)

;~ Lets see what we got from the search
    Local $oBBTable = _IETableGetCollection($oIE, 2)
    $aBBTableData = _IETableWriteToArray($oBBTable)
    _ArrayDisplay($aBBTableData)

    DeleteCourseBegin()

EndFunc   ;==>SearchCourse



;~ OK, we logged in and we searched for a course. Lets delete it!
Func DeleteCourseBegin()
    $iSearchIndex = _ArraySearch($aBBTableData, "Course ID", 0, 0, 0, 1, 1, 0)

;~  If the course was not found, do this.
    If $iSearchIndex = -1 Then
        MsgBox(4096, "Search Error", "Item not found")
        $sResult = "No"
;~  Now go back to the Excel sheet and search for the next one....?

;~ If the course was found, begin the deletion process.
    Else
        $aSearchResult
        MsgBox(4096, "Search Success", $aBBTableData[$iSearchIndex][0] & " = " & $aBBTableData[$iSearchIndex][1])
        DeleteCourseNow()
        $sResult = "Yes"
    EndIf
    Return $sResult
EndFunc   ;==>DeleteCourseBegin

;~ The course search was successful. Delete the course now.
Func DeleteCourseNow()
;~ Click the checkbox located beside the course that has been found.
    Local $CheckBox = _IEGetObjByName($oIE, "ckbox")
    _IEAction($CheckBox, "click")
    _IELoadWait($oIE)

;~ Click the Delete button.
    _IELinkGetCollection($oIE)
    Local $oLinks = _IELinkGetCollection($oIE)
    For $oLink In $oLinks
        If $oLink.href = "javascript:validateRemove();" Then
            _IEAction($oLink, "click")
            ExitLoop
        EndIf
    Next

;~  Click the "Delete course, including all of its files" radio button.
    Local $RadioButton = _IEGetObjById($oIE, "removeAllFiles_t")
    _IEAction($RadioButton, "click")
    _IELoadWait($oIE)

;~ Click the "Submit" button
    Local $Submit = _IEGetObjByName($oIE, "bottom_Submit")
    _IEAction($Submit, "click")
    _IELoadWait($oIE)
;~  Now go back to the Excel sheet and search for the next one....?

EndFunc   ;==>DeleteCourseNow

 

So, is this being caused by how I have everything residing within a Func? Because at the end of each func, I call upon another one. Is that not a good way to go about it? :huh2:

I can't do something like Func SearchCourse($aSearchResult) this way?

 

Share this post


Link to post
Share on other sites

OK, but still getting the same error (SearchCourse() called by a previous line with 0 arg(s)) because of...

$aSearchResult[$i] = SearchCourse($aSearchItems[$i])

^located in the OpenExcel() func :think:

Share this post


Link to post
Share on other sites

No The error means you've called SearchCourse without any parameter, so look for the following and remove it since its been called within the loop.

SearchCourse()

 

Share this post


Link to post
Share on other sites

OhHhHHhHHHh my bad! I get it. It was already there and I put it in again with 0 arg. amirite?

Alright that error is gone! :lol:

Now I'm getting Statement cannot be just an expression regarding $aSearchResult in the Else...

;~ OK, we logged in and we searched for a course. Lets delete it!
Func DeleteCourseBegin()
    $iSearchIndex = _ArraySearch($aBBTableData, "Course ID", 0, 0, 0, 1, 1, 0)

;~  If the course was not found, do this.
    If $iSearchIndex = -1 Then
        MsgBox(4096, "Search Error", "Item not found")
        $sResult = "No"
;~  Now go back to the Excel sheet and search for the next one....?

;~ If the course was found, begin the deletion process.
    Else
        $aSearchResult
        MsgBox(4096, "Search Success", $aBBTableData[$iSearchIndex][0] & " = " & $aBBTableData[$iSearchIndex][1])
        DeleteCourseNow()
        $sResult = "Yes"
    EndIf
    Return $sResult
EndFunc   ;==>DeleteCourseBegin

 

Share this post


Link to post
Share on other sites

Hmmm, still getting the same error

;~ OK, we logged in and we searched for a course. Lets delete it!
Func DeleteCourseBegin()
    Local $sResult
    $iSearchIndex = _ArraySearch($aBBTableData, "Course ID", 0, 0, 0, 1, 1, 0)

;~  If the course was not found, do this.
    If $iSearchIndex = -1 Then
        MsgBox(4096, "Search Error", "Item not found")
        $sResult = "No"
;~  Now go back to the Excel sheet and search for the next one....?

;~ If the course was found, begin the deletion process.
    Else
        $aSearchResult
        MsgBox(4096, "Search Success", $aBBTableData[$iSearchIndex][0] & " = " & $aBBTableData[$iSearchIndex][1])
        DeleteCourseNow()
        $sResult = "Yes"
    EndIf
    Return $sResult
EndFunc   ;==>DeleteCourseBegin

image.thumb.png.524dd4e53ca41f00296096e748043913.png

Share this post


Link to post
Share on other sites

its working now :dance:

This is so cool. It doing the thing. :yes:

And when there's no more it puts a "0" into column B.

THANK YOU!!!!!!1

 

Share this post


Link to post
Share on other sites

"And when there's no more it puts a "0" into column B."

Do you mean it does have Yes or No in column B?  What does _ArrayDisplay($aSearchResult, "Search Results") return?

Share this post


Link to post
Share on other sites

This

image.png.2c285ca37891a34bc051f37522921fea.png

It doesn't enter "Yes" or "No" at any point. It only throws a bunch of zero's into column B at the very end.

 

Edited by XinYoung
Elaboration

Share this post


Link to post
Share on other sites

Sorry a bit difficult to write code without testing, but you should be able to fix this by changing the SearchCourse(..) function, adding Return DeleteCourseBegin

;~  Now that were logged in, navigate to the course search page.
Func SearchCourse($_sSearchItem)
    _IENavigate($oIE, $urlBBCourseSearch)

    ;~  Change the search criteria to "Course ID"
    _bbCourseSearchCategoryChange("Course ID")

;~ Paste whats copied into the search text box and click submit
    Local $oForm = _IEGetObjByName($oIE, "courseManagerFormSearch")
    Local $oSearchString = _IEFormElementGetObjByName($oForm, "courseInfoSearchText")
    _IEFormElementSetValue($oSearchString, $_sSearchItem)
    _IEFormSubmit($oForm)

;~ Lets see what we got from the search
    Local $oBBTable = _IETableGetCollection($oIE, 2)
    $aBBTableData = _IETableWriteToArray($oBBTable)
    _ArrayDisplay($aBBTableData)

    Return DeleteCourseBegin()
EndFunc   ;==>SearchCourse

 

Share this post


Link to post
Share on other sites

Hey, um, what do I change here to make it always target a sheet named "DeleteCourses" in my Excel workbook? Sometimes the file was saved on a different sheet, which causes the wrong sheet to be Active.

Func OpenExcel()
    Global $aBBTableData
    Global $oExcel = _Excel_Open()
    Global $oWorkbook = _Excel_BookOpen($oExcel, $ChosenFileName, Default, Default, True)
;~ Get all used cells in column A:A
    Global $aSearchItems = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"))
;~ Duplicate the $aSearchItems Array
    Global $aSearchResult = $aSearchItems
;~ Loop through $aSearchItems
;~ Since Excel_RangeRead returns a 0-based Array and since we only captured one column it is a 1 dimension array
;~ Loop through the array starting at 0 until the end of the array which is (Ubound($aSearchItems) - 1)
    For $i = 0 To UBound($aSearchItems) - 1
        $aSearchResult[$i] = SearchCourse($aSearchItems[$i])
    Next
    _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "B1")
    Finished()
EndFunc   ;==>OpenExcel

Thanks again

Share this post


Link to post
Share on other sites
56 minutes ago, XinYoung said:

what do I change here to make it always target a sheet named "DeleteCourses"

 

Assuming that the sheet actually exists, the following line will make sure that the sheet is active:

$oExcel.Sheets("DeleteCourses").Activate

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Cristin
      Dear all,
      first of all hi.
      I`m in trouble, again 😕
      I can`t find right solution, tried all possible combinations generated by my mind and nothing.
      I need to copy range of values depending by values from two different cells in excel sheet.
      I put an example in attachment.

      I have two values which is never changed (is changed only TEXT). I need to copy all the rows from VALUE 1 to VALUE 2 in new Sheets (Output 1, Output 2, ... , Output X).
      It is possible to do this using Autoit? 🤔
      Also in attachment you can find last example which I have tried and it`s something near, it is copying by _Excel_RangeFind row with needed VALUE 1 but I need to copy whole range from VALUE 1 to VALUE 2 😵 ( see in attachment examples).
      Thank you very much, in advance, for your support, solution really will make my life much easier 🙃
      Have a nice day all of you!
      Best Regards,
      Cristin
      Book1.xlsx something.au3
    • By sudeepjd
      I was looking for a UDF using which I could Add and Update Pivot tables and Pivot Charts in Excel easily and could not find one that I could use. So I build this UDF. 
      It has the following functions :
      _ExcelPivot_CreateCache ; Easily Create a pivot table data cache from a Sheet _ExcelPivot_CreateTable ; Create a table from a cache at a specified location on the sheet _ExcelPivot_RefreshTable ; Refresh the datatable data with a new cache _ExcelPivot_AddField ; Add a Field and Aggregate function to the Datatable _ExcelPivot_AddFilter ; Adds in the Filter to a specific field _ExcelPivot_ClearFilter ; Removes the filter for a field or all the filters in the table _ExcelPivot_GetRange ; Get specific areas of a Pivot as a Range Object _ExcelPivot_AddChart ; Add a Pivot Chart linked to a specific Pivot table Attached the UDF to this post.
      Please do let me know if I can improve or add additional functions to it.
      A detailed example on the usage is below. The excel file and the example can be downloaded from the Example.zip file attached.
      #include "ExcelPivot.au3" $oExcel = _Excel_Open() $oBook = _Excel_BookOpen($oExcel, @ScriptDir & "\TestPivot.xlsx") ;Create a Sheet to put the pivot into $pSheet = _Excel_SheetAdd($oBook, -1, False, 1) $pSheet.Name = "Pivot" ;Get the cache for the pivot table $pCache = _ExcelPivot_CreateCache($oBook, "Data") ;Add in the Pivot Table from the Cache _ExcelPivot_CreateTable($pCache, $pSheet, "A1", "FruitsPivot") ;Add in the Fields into the Pivot _ExcelPivot_AddField($pSheet, "FruitsPivot", "Category", "Filter") _ExcelPivot_AddField($pSheet, "FruitsPivot", "Product", "Row") _ExcelPivot_AddField($pSheet, "FruitsPivot", "Amount", "Value", "Sum", 1) ;Add in a Running total to the Pivot _ExcelPivot_AddField($pSheet, "FruitsPivot", "Amount", "Value", "Sum", 2, "PercentageRunningTotal", "Product") ;Filter only the fruits _ExcelPivot_Filter($pSheet, "FruitsPivot", "Category", "Fruit") ;Draw a Paretto Chart $chart = _ExcelPivot_AddChart($oBook, $pSheet, "FruitsPivot", "ColumnClustered", "Paretto", "E2", 570) $chart.Chart.FullSeriesCollection(1).ApplyDataLabels $chart.Chart.FullSeriesCollection(2).ChartType = 4 ;Change the percentage to a line graph $chart.Chart.FullSeriesCollection(2).AxisGroup = 2 ;Move it to secondary axis $chart.Chart.Axes(2, 2).MaximumScale = 1 ;Adjust to scale to 100% max  
       
      ExcelPivot.au3 Example.zip
    • By Page2PagePro
      Excel VBA's IDE registers a Control-y as "cut this line of code".
      For those prone to Undo/Redo (Ctrl+Z/Ctrl+Y) you may find frustration when your code in the editor does not redo, but in fact clears your active line of code while killing redo history.
      Though not perfect, I keep this tool running in background on startup.
      The purpose is to allow Cltr+Y to act normally throughout Windows and Office and only interact *differently* with the "Microsoft Visual Basic for Applications" window that is active.
      If the Standard Menu bar exists, it'll try to click the ReDo (Blue Arrow to the right), else "Alt+e, r" keystrokes (less desired).
       
      Here's the code:
      Opt('MustDeclareVars', 1) Opt("WinTitleMatchMode", 1) HotKeySet("^y", "TriggerRedo") While 1 Sleep(10) WEnd Func TriggerRedo() ConsoleWrite("TriggerRedo()" & @CRLF) Local $title = "Microsoft Visual Basic for Applications - " Local $hWnd If WinExists($title) And WinActive($title) Then ;~ Parent Window Handle $hWnd = WinGetHandle($title) Local $aWindowPos = WinGetPos($hWnd) ;~ Control Bar Handle, Position and If Visible Local $sControlID = "[CLASS:MsoCommandBar; TEXT:Standard;]" Local $hStandardBar = ControlGetHandle($hWnd, "", $sControlID) Local $bIsVisible = ControlCommand($hWnd, "", $sControlID, "IsVisible") If $hStandardBar And $bIsVisible Then ConsoleWrite("Using Mouse Click." & @CRLF) ;~ Determine Redo button location on visible Control Bar Local $aBarPos = ControlGetPos($hWnd, "", $sControlID) Local $mX = $aWindowPos[0] + $aBarPos[0] + 217 + Int(23/2) Local $mY = $aWindowPos[1] + $aBarPos[1] + 27 + Int(22/2) MouseClick("Left", $mX, $mY, 1, 0) Else ConsoleWrite("Using VBA Send Keys." & @CRLF) $sControlID = "[CLASS:MsoCommandBar; TEXT:Menu Bar;]" Local $hMenuBar = ControlGetHandle($hWnd, "", $sControlID) ControlSend($hWnd, "", $hMenuBar, "!e") ;~ Send("r") $sControlID = "[CLASS:MsoCommandBarPopup; TEXT:Edit;]" Local $hPopupBar = ControlGetHandle($hWnd, "", $sControlID) ControlSend($hWnd, "", $hPopupBar, "r") EndIf Else ConsoleWrite("Using NATIVE Send Keys." & @CRLF) HotKeySet("^y") Send("^y") ;~ may cause "yyy..." when held HotKeySet("^y", "TriggerRedo") EndIf EndFunc ;==>TriggerRedo Hope this inspires someone.
       
       
    • By siawpo
      Hi,
      I'd like to change different colors for different portion of text in same cell of Excel application.
      Neither character length nor cell might not fixed.
      Here's the code I've tried to put together but not manage to pull it off.
      I'm appreciate it for any suggestion, thank you.
      $oExcel = ObjCreate("Excel.Application") With $oExcel ; open new workbook .Visible = True .WorkBooks.Add .ActiveWorkbook.Sheets(1).Select() EndWith $oExcel.Cells.Font.Color = 0x000000 $oExcel.ActiveFont.Color = -16776961 Send ("'I'd like this sentence to be red'") Sleep(100) Send ("{AltDown}{Enter}{AltUp}") Sleep(100) $oExcel.ActiveCell.Selection.Font.Color = 0x000000 Send ("'I like this sentence to be black'") Sleep(100) Send ("{AltDown}{Enter}{AltUp}") Sleep(100) $oExcel.ActiveFont.Color = -16776961 Send ("'I'd like this sentence to be red again'") Sleep(100) Send ("{AltDown}{Enter}{AltUp}") Sleep(100) Send("{ENTER}")  
    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
×
×
  • Create New...