Jump to content

Recommended Posts

jaja714

For years, I have been running a script using ObjGet to open an Excel workbook but, after upgrading from Win7 to Win10, ObjGet is now returning with an error.  The only way I can get it to work on Win10 is to actually open the workbook manually myself and then run the script.

Share this post


Link to post
Share on other sites
JLogan3o13

@jaja714 what would you like us to do to assist without seeing the code you're using?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
water

Why do it "manually"? AutoIt comes with an Excel UDF.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
jaja714

Ahah, I am always open to a better way.  here is what I have been doing for many years ... until Win10 ;)

 

$FileName = "C:\Users\Public\Music\The Beatles\The Beatles.xlsx"
$CellRange="songs"                                      ; Change this to the range of cells you want to modify

if not FileExists($FileName) then                       ; Just a check to be sure..
    Msgbox (0,"loadBeatles","Error: Can't find file " & $FileName)
    SetError(1)
    Return
endif

$oExcelDoc = ObjGet($FileName)                          ; Get an Excel Object from an existing filename
                                                        ; NOTE: $oExcelDoc is a "Workbook Object", not Excel itself!
If (not @error) and IsObj($oExcelDoc) then              ; Check again if everything went well
    $oDocument=$oExcelDoc.Worksheets(1)                 ; We use the 'Default' worksheet
    $aBeatles=$oDocument.range($CellRange).value        ; Retrieve the cell values from given range

    ; The data should now be in the 2-dimensional array: $aBeatles
    If Not IsArray($aBeatles) And Ubound($aBeatles,0) < 5 Then
        Msgbox (0,"loadBeatles","Error: Could not retrieve data from cell range: " & $CellRange)
        SetError(1)
    EndIf

    $oExcelDoc.saved=1              ; Prevent questions from excel to save the file
    $oExcelDoc.close                ; Get rid of Excel.
Else
    Msgbox (0,"loadBeatles","Error: Could not open "& $FileName & " as an Excel Object.")
    SetError(1)
Endif

Return $aBeatles

 

Share this post


Link to post
Share on other sites
water

Did you just upgrade the OS or Office as well?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
jaja714

Duh ... yes ... Office 2016!  I did em both the same day.

 

Share this post


Link to post
Share on other sites
water

So something has changed when upgrading Office.
Can you elaborate on which error you get? What's the value of @error? Do you get error messages?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Is this a trial version of Office 2016 or did you upgrade from a trial version?

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
jaja714

Is this a trial version of Office 2016 or did you upgrade from a trial version?

 

This is the real version of Office 2016.

I didn't think the value of @error was important as the documentation simply says it will be non-zero when failing.  For what it's worth though, the value of @error is -2147221018.

Share this post


Link to post
Share on other sites
water

When converted to hex -2147221018 is equal to 0x800401E6 and stands for "MK_E_INVALIDEXTENSION Bad extension for file." - Whatever this means.
https://msdn.microsoft.com/en-us/library/cc704587.aspx


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

When searching the web for "excel hresult 0x800401E6" it seems that the error tells you that the file you want to access is already opened by another application:
https://stackoverflow.com/questions/24323167/waiting-open-excel-when-program-is-writing-data-to-excel

So I suggest to use the Excel UDF to work with Excel workbooks.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
jaja714

Well, the file is certainly not open by another applications and further, the extension .xlsx is perfectly fine as well.

On the contrary, I am actually able to get my script to run successfully if I actually do open the file before running the script.  Strange.

Sounds like ObjGet and Office2016 are not playing nice.  Let me look into the whole Excel UFD thing...

Share this post


Link to post
Share on other sites
jaja714

.

Edited by jaja714

Share this post


Link to post
Share on other sites
water

_Excel_Open, _Excel_BookOpen and _Excel_RangeRead should do what you need.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
jaja714

What?  Still getting the same error as before!  The only difference is that it is _Excel_Open returning the error instead of ObjGet.

Also, just like before, _Excel_Open works fine if the workbook in question is already open.

NOTE: @extended = -2147221164

$oExcel = _Excel_Open(False,False,False,False,True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "loadBeatles", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

$oWorkbook = _Excel_BookOpen($oExcel, $wbBeatles, Default, Default, True)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "loadBeatles", "Error opening workbook '" & $wbBeatles & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
EndIf

$aBeatles = _Excel_RangeRead($oWorkbook, Default, $cellRange)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "loadBeatles", "Error reading range " & $cellRange & @CRLF & "@error = " & @error & ", @extended = " & @extended)

 

Edited by jaja714
add @extended

Share this post


Link to post
Share on other sites
water

This error code stands for:
0x80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
Seems that Excel is not installed or not available to the user who runs the script.
Do you run the script from the task scheduler or as user System?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
jaja714

When I build an EXE and run as admin, I get the same error as above.  Am I the first Autoit programmer to use Excel UDF for Office 2016?

Share this post


Link to post
Share on other sites
water

This is not my area of expertise but I think it is a problem with Excel not being registered for all users.
I'm sure you will find a solution on the web.
Or maybe another user knows how to solve this problem.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
jaja714

I'm not sure what "registered for all users" means.  I am the only user and, further, Excel 2016 shows me as "signed in" whenever I open it.

What in the world should I search for on the web?

Would it be easier to simply debug the Excel UDF on my machine?

Share this post


Link to post
Share on other sites
jaja714

Ok, so I did some debugging of the existing Excel UDF and ... we are right back where we started ... ObjGet and ObjCreate!!!

ObjGet returns 0 for both @error and @extended while ObjCreate returns @error = -2147221164 and @extended = 0.

 

p.s. how do you look up the values of these error codes?  It would be nice if there were some sort of ShowError and ShowExtended functions!

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

  • Similar Content

    • Skeletor
      By Skeletor
      Hi Guys,
      Can anyone point me in the right direction. I'm trying to accomplished conditional formatting with arrows, but the code I have is wrong... 
      .Range("=$A3:$A4000").FormatConditions.Add = (xlCellValue, xlGreater, "=$A:$A") .IconSet(xl3Arrows) ;ActiveWorkbook.iconsets I also tried it like this:
      .Range("=$A3:$A4000").FormatConditions _ .Add(xlCellValue, xlGreater, "=$A:$A") .IconSet(xl3Arrows) ;ActiveWorkbook.iconsets  
    • Skeletor
      By Skeletor
      Hi Guys,
      How would you use _Excel_FilterSet to filter the excel sheet from largest number to smallest number?
      _Excel_FilterSet($oWorkbook, "Sheet1", "A2:I2", 1, ">20", 1, "<40") ; OR _Excel_FilterSet($oWorkbook, "Sheet1", "A2:I2", 1, ">", 1, "<") Excel Sheet attached. Trying to filter on the last column "I2"
      Inventory.xlsx
    • faustf
      By faustf
      hi guys
      i have a script  like this,  in windows 7 work perfect , in windows 10 not  work  , some one can explain me  why ??'
      #include <Array.au3> #include <MsgBoxConstants.au3> Global $aGPathFoto= FileReadToArray (@ScriptDir & "\TEMP\PathFoto.txt") Local $ctrl = 0 While 1 Local $hWnd = WinWait("[CLASS:#32770]", "", 10) If WinExists("[CLASS:#32770]") Then If $ctrl < 2 Then ControlSend($hWnd, "Choose File to Upload", "[CLASS:Edit; INSTANCE:1]", $aGPathFoto[0]&"{Enter}") Exit $ctrl += 1 Else ExitLoop EndIf EndIf WEnd $aGpathfoto = C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg
    • Skeletor
      By Skeletor
      Hi All,
      Has anyone come across this before?
      Code below:
      $SheetList = _Excel_SheetList($oWorkbook) _FileWriteFromArray("C:\" & $SheetListOutput, $SheetList, 1) Result:
      ResultABC| ResultDEF| ResultGHI| ResultJKL| ResultMNO| It created these "|" vertical bars?
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
×