Jump to content

Recommended Posts

Posted

Hi!

I have a simple question about how to use the .Index in AutoIt code?

Example:

$oExcel.WorkSheets("SheetName").Index

For some reason AutoIt don't want to take it.

More specificly I need to use it this way:

$iLastSheet = $oExcel.WorkSheets($oExcel.WorkSheets.Count).Index

I need an integer variable that will be the index of the last Sheet.

My goal is to loop from the 4th sheet to the last sheet like the following:

For $i = 4 To $iLastSheet

$oSheet = $oExcel.Worksheets($i)

"Some action taken on the sheet ..."

Next

Any help would be verry apreciated!

Thanks!

Posted

Have a look at the function _ExcelSheetList in the Excel UDF.

Func _ExcelSheetList($oExcel)
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    Local $iTemp = $oExcel.ActiveWorkbook.Sheets.Count
    Local $aSheets[$iTemp + 1]
    $aSheets[0] = $iTemp
    For $xx = 1 To $iTemp
        $aSheets[$xx] = $oExcel.ActiveWorkbook.Sheets($xx).Name
    Next
    Return $aSheets
EndFunc ;==>_ExcelSheetList

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Thank you very much Water for this quick reply.

But you will laugh at me cause I'm laughing at me myself!

I pass the whole night coding and in fact the .index statement is working as it should!

The reason why nothing was working is that I forgot to put call statement to my Func in my code!

I was trying to debug with some MsgBox and of course the reason why no MsgBox was showing and also no error was showing is that my Func was not even called at a single point of my script!

I'm sorry it's my big mistake!

Posted

Don't worry!

That's something that happens to me from time to time as well :blink:

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
×
×
  • Create New...