Jump to content
hyperjase

_Excel_RangeRead - returning File Not Found

Recommended Posts

hyperjase

I created a script a few years ago to go into multiple Excel files and iterate through all the sheet names (these files are test data which have multiple sheets) then selects certain cells dependant on which sheet is currently selected.

The code ran absolutely perfectly and I've adapted it slightly to read a cell I haven't selected before, but annoyingly, every time I run the script, that cell returns "File Not Found", but when I select the cell directly above this, it returns the cell value!

The "File Not Found" error appears to be a little misleading as the file is open and being read, I just assume that it means it can't find the data in that cell -- which happens to be a 10 digit decimal value.

Have I missed something really simple here?

Share this post


Link to post
Share on other sites
water

The Excel UDF has completely been rewritten. Which function calls do you use? _Excel* or _Excel_*


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
hyperjase

Ah - thanks for this, I updated my AutoIT software yesterday so I would imagine it may well have changed but my one line of code in question is:

_Excel_RangeRead($DataDump, $eArray[$j][0], "AH5")

The $eArray is the sheet array name.

Share this post


Link to post
Share on other sites
JLogan3o13

Moved to the correct forum, as the DEV forum very..clearly..states:

Quote

Do not create AutoIt-related topics here, use AutoIt General Help and Support

We even bolded it


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

Share this post


Link to post
Share on other sites
hyperjase

My apologies!

Share this post


Link to post
Share on other sites
water

Can you please post the messages you see in the SciTE output pane?
And the value of @error and @extended after _Excel_RangeRead would be very helpful!


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
hyperjase

I've formatted it so it should be readable -- oddly, the first time I ran this IT WORKED ... now it doesn't!!

File open: 5572.XLSM
This should be a value: File Not Found
@error = 0
@extended =  0
Close Book = 1
File open: 5571.XLSM
This should be a value: File Not Found
@error = 0
@extended =  0
Close Book = 1

 

Share this post


Link to post
Share on other sites
water

Unfortunately this doesn't help very much. Can you post your script as well?


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
hyperjase

Here's the lot as-is

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=excel-icon-15.ico
#AutoIt3Wrapper_Outfile=Excel to SQL Import.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <File.au3>
#include <Excel.au3>
#include <Array.au3>
#include <Date.au3>
#include <String.au3>
#include <StringConstants.au3>

$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Open("Provider=SQLOLEDB.1;Data Source=Server;Initial Catalog=DB","user","password")

Dim $files, $newArray[1], $i, $j
$oExcel = _Excel_Open(False, False, True, True)
$files = FileOpenDialog("Please select the files (must be 2 or more)", "\\Server\Production Tests\", "Excel (*.xlsm)|Excel (*.xls)", 4)
$numFiles = StringSplit($files, "|")

$Path = _ArrayExtract($numFiles, 1, 1)
$numFiles = _ArrayExtract($numFiles, 2)

;$type = InputBox("Please give this a title","What are these type?")

For $i = 0 To UBound($numFiles)
    If $i = UBound($numFiles) Then ExitLoop
    $fileName = $Path[0] & "\" & $numFiles[$i]
    $fileType = _StringExplode($numFiles[$i]," ")
    $DataDump = _Excel_BookOpen($oExcel, $fileName, True, False, "", "", 0)
    ConsoleWrite("File open: " & $numFiles[$i] & @CRLF)
    $eArray = _Excel_SheetList($DataDump)

    For $j = 0 To UBound($eArray)
        If $j = UBound($eArray) Then ExitLoop
        $FileTime = FileGetTime($fileName,$FT_MODIFIED,0)
        $NewFileTime = $FileTime[0] & "-" & $FileTime[1] & "-" & $FileTime[2]

        If $eArray[$j][0] = 'Control Panel' Then
            ConsoleWrite("This should be a value: " & _Excel_RangeRead($DataDump, $eArray[$j][0], "AH5") & @CRLF)
            ConsoleWrite("@error = " & @error & @CRLF)
            ConsoleWrite("@extended =  " & @extended & @CRLF)
        EndIf

        ReDim $newArray[1]
        $newArray[0] = ''

    Next
    $closeBook = _Excel_BookClose($DataDump,False)
    ConsoleWrite("Close Book = " & $closeBook & @CRLF)
Next
$sqlCon.Close
_Excel_Close($oExcel, False)
;MsgBox(0,"Finished!","All files have been imported into SQL")

 

Share this post


Link to post
Share on other sites
water
If $eArray[$j][0] = 'Control Panel' Then
            ConsoleWrite("This should be a value: " & _Excel_RangeRead($DataDump, $eArray[$j][0], "AH5") & @CRLF)

Seems cell "AH5" of sheet "Control Panel" of the workbook "5572.XLSM" holds the value "File Not Found".

Can you please check this manually?


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
hyperjase

I have a feeling this is because it's actually linked to another file via Visual Basic -- but when the file loads, it must put the value into that cell as it's not a reference for another cell on another sheet - on that basis that's why I've selected that cell.  If that's the case is there a way of allowing the Visual Basic to run prior to picking up the value?

Share this post


Link to post
Share on other sites
water

Is this a script automatically executed when the Workbook gets loaded? Maybe inserting a Sleep statement to your script will do the trick?


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
hyperjase
Posted (edited)

That sounds like a plan, I'll give that a try, many thanks!

 

-----UPDATE

Would appear that "File Not Found" is actually what is in the Cell -- loading the Excel file standalone loads the values correctly, but when AutoIT opens it, no code runs and doesn't populate the value!

At this point, it's not a deal-breaker in terms of what I'm trying to achieve so I'll leave that cell alone.

Thank you for your assistance with this.

Edited by hyperjase

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

×