jaja714

Excel ObjGet Windows 10

25 posts in this topic

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



@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

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

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

Did you just upgrade the OS or Office as well?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

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

 

Share this post


Link to post
Share on other sites

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

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

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

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

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

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

#13 ·  Posted (edited)

.

Edited by jaja714

Share this post


Link to post
Share on other sites

_Excel_Open, _Excel_BookOpen and _Excel_RangeRead should do what you need.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

#15 ·  Posted (edited)

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

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

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

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

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

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

    • LoneWolf_2106
      By LoneWolf_2106
      Hi,
      i have an error:
      ==> The requested action with this object has failed.: $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count $iRowCount = .Range(^ ERROR  
      My code is:
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) Sleep(1000) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count Sleep(1000) _Excel_RangeWrite($oWorkbook_1, $oWorkbook_1.ActiveSheet,$aFileList[$i][2] , "AB3:AB"&$iRowCount) I have added some sleep because the application was crashing more often before, so i thought to slow down the code execution.
      But i didn't solve the issue.
      Has anyone an idea of what the problem might be?
      Thanks in advance.
    • water
      By water
      Extensive library to control and manipulate Microsoft Excel charts.
      Written by GreenCan and water.
      Theads: General Help & Support - Example Scripts
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2017-07-21)
      None. The COM error handling related bugs have been fixed.
       
    • LoneWolf_2106
      By LoneWolf_2106
      Hi,
      i have a problem with the deletion of an empty row in Excel.
      My code:
       
      If $vRow_2 = "" Then _Excel_RangeDelete($oWorkbook_1.ActiveSheet,"2", $xlShiftUp,1) EndIf I want to delete the second row. $vRow_2 is an empty cell, "A2".
      After running the code, the second row is not deleted.
      I have tried also:
       
      If $vRow_2 = Null Then _Excel_RangeDelete($oWorkbook_1.ActiveSheet,"2", $xlShiftUp,1) EndIf But it doesn't work.
      Any suggestion?
      Thanks in advance.
    • BBs19
      By BBs19
      Features:
      Create modern looking borderless and resizable GUIs with control buttons (Close,Maximize/Restore,Minimize, Fullscreen, Menu) True borderless, resizeable GUI with full support for aerosnap etc. Many color schemes/themes included. See MetroThemes.au3 for more details. 3 type of Windows 8/10 style buttons. Modern checkboxes, radios, toggles and progressbar. All buttons, checkboxes etc. have hover effects! Windows 10 style modern MsgBox. Windows 10/Android style menu that slides in from left. Windows 10 style right click menu  
      Credits: @UEZ, for the function to create buttons with text using GDIPlus. @binhnx for his SSCtrlHover UDF
       
      Changelog:
      Download UDF with example:
       
       
    • VeryGut
      By VeryGut
      I'm trying to insert the following formula in cell A2 using my script:
      =if(A1=""; "YES"; "NO")
      To my understanding, the line of code should be similar to this:
      _Excel_RangeWrite($MasterFile, Default, "=if(A1=""; "YES"; "NO")", "A2")
      However, it does not work, probably due to the multiple quotation marks that confuse the script :C
      How do I avoid this problem?