Jump to content

Recommended Posts

Posted

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?

Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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.

  • Moderators
Posted

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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

 

Posted

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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")

 

Posted
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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?

Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

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
×
×
  • Create New...