Jump to content
Sign in to follow this  
Fatum48

Excel Simple question about the .Index statement

Recommended Posts

Fatum48

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!

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Fatum48

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!

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  

×