Jump to content

Erorr with type object on $oExcelWorkbook.ActiveSheet.Name


Mkhan
 Share

Recommended Posts

I am running a series of tasks in excel with the help of Autoit. I've relied on the material online to get so far and have been running my scripts for sometime now. The script works fine, for weeks without issues, but sometimes I get this error. Usually if I reboot the system and re-run the scripts the issues resolves itself but I cant seem to get past it this time.

I am using  $oExcelWorkbook.ActiveSheet.Name to get the name of my active sheet. I want to check the name of the active sheet and change it to the sheet I want it to be , if it is not that sheet. Below is a snippet of the code.

 

;Open file
      Global $oExcel = _Excel_Open()
      Global $sFilePathDailyOP = "C:\Users\...."
      $oDailyOP = _Excel_BookOpen($oExcel, $sFilePathDailyOP)
      Sleep(10000)
     

;Adjust sheet selection
      Local $sCurrentsheet = $oDailyOP.ActiveSheet.Name  ; THIS IS THE LINE I Get the Error At
      Local $sSheetneeded = "PI 5 sec Data"
         If $sCurrentsheet <> $sSheetneeded Then
         $oDailyOP.Sheets("PI 5 sec Data").Select
         EndIf
      $oDailyOP.ActiveSheet.Range("A8:BB17288").Select
      Sleep(1000)

 

Here's a snippet of the error

image.png.06fba12f48458fad19dd6863e9917bb2.png

I would appreciate any help with the error. Thank you

Link to comment
Share on other sites

6 minutes ago, Danp2 said:

_Excel_BookOpen is likely failing to open the workbook. You should check the value of @error immediately after calling this function to see why it is failing.

I added this after _ExcelOpen() : MsgBox(0, "", "Open: " & @error)

and this after _EXCEL_BookOpen() : MsgBox(0, "", "BookOpen: " & @error)

Got these Messages

image.png.4ec83e89d1c5ba6af152730e458b75d3.png

 

image.png.b6a3a683f79047cc9d978ae0f564cf0d.png

 

How do I check what this means.

 

Link to comment
Share on other sites

28 minutes ago, Mkhan said:

I added this after _ExcelOpen() : MsgBox(0, "", "Open: " & @error)

and this after _EXCEL_BookOpen() : MsgBox(0, "", "BookOpen: " & @error)

Got these Messages

image.png.4ec83e89d1c5ba6af152730e458b75d3.png

 

image.png.b6a3a683f79047cc9d978ae0f564cf0d.png

 

How do I check what this means.

 

My script has a loop in which I am creating the excel file by copying from a previous version and naming it differently. I am using FileCopy () for that. The script seems to have trouble creating a copy of the excel file in some instances and as a result BookOpen fails because the file was not created. S

Before I close the excel is saved, but in some instances autoit is having trouble saving the file as well, resulting in not have a file to copy when the loop restarts. I use _Excel_Close($oWorkbook) to close the excel.

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...