Jump to content

Excel.au3 Error


Recommended Posts

I'm trying to activate a Sheet on an Excel File with the below code

Non-working Code

Local $sExcelSheets = ""
    Local $aExcelSheets = _ExcelSheetList($oExcel)
    
    If $switch = "SUAW" Then
        For $i = $aExcelSheets[0] To 1 Step -1 ;Work backwards through loop
            If StringInStr($aExcelSheets[$i], "Approv") Then ;Using the String Name returned in the Array Elements
                $sExcelSheets = $aExcelSheets[$i]
            EndIf
            If $sExcelSheets <> "" Then ExitLoop
        Next
    ElseIf $switch = "UserLoader" Then
        For $i = $aExcelSheets[0] To 1 Step -1 ;Work backwards through loop
            If StringCompare($aExcelSheets[$i],"Users")=0 Then ;Using the String Name returned in the Array Elements
                $sExcelSheets = $aExcelSheets[$i]
            EndIf
            If $sExcelSheets <> "" Then ExitLoop
        Next
    EndIf
    If $sExcelSheets = "" Then
        _ErrorProgressBar()
        MsgBox(0, "Error", "   Unable to find the correct tab.   ")
        Exit
    Else
        _ExcelSheetActivate($oExcel, $sExcelSheets)
        _Main()
    EndIf

What's odd is that as standalone code it works without any errors (below). With the rest of my code I get the below error:

$oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value = $sValue

$oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value = $sValue^ ERROR

Any help is appreciated.

Working Temp Code

#include <Excel.au3>
#include <Array.au3>

  $oExcel = _ExcelBookOpen(@DesktopDir & "\Users.xls")
  Local $sExcelSheets = ""
  Local $aExcelSheets = _ExcelSheetList($oExcel)
  For $i = $aExcelSheets[0] To 1 Step -1 ;Work backwards through loop
    If StringCompare($aExcelSheets[$i],"Users")=0 Then ;Using the String Name returned in the Array Elements
      $sExcelSheets = $aExcelSheets[$i]
    EndIf
    If $sExcelSheets <> "" Then ExitLoop
  Next
  _ExcelSheetActivate($oExcel, $sExcelSheets)
Exit

-Work Smarter, Not Harder, Use More AutoIT

Link to comment
Share on other sites

could it be you're using exitloop instead of continueloop?

[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Link to comment
Share on other sites

could it be you're using exitloop instead of continueloop?

I ExitLoop if the Tab matches the name so that's working as expected. Plus it's the same in the standalone vs the bulk code. The standalone works as is.

WEIRD :)

-Work Smarter, Not Harder, Use More AutoIT

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...