Jump to content

excel.au3 UDF question


 Share

Recommended Posts

Hi Everyone,

I'm new to this forum and have been playing with AutoIt for a little awhile now. First off, let me say "Thanks!!" to all the contributors. It has been fun learning how to use it. I've got a question that I think has a simple solution, but have not found it on the site yet.

I have a script that basically utilizes the excel.au3 from Locodarwin (http://www.autoitscript.com/forum/index.php?showtopic=34302&hl=excel+udf). All it does for now is:

1. call _ExcelBookOpen() to open an existing excel book that contains a list of file names

2. call _ExcelReadCell() to read the values in each cell and puts it in an array list for me to use later on.

3. call _ExcelBookClose() to close

Fairly simple and works just fine on the system that I've used to written the script in.

The problem is that once I compile the script and execute the exe on another system, it errors stating that it cannot open Excel.au3 which I've included in the beginning of the script with #include <Excel.au3>. My understanding is that once compiled, all include function should be included and I won't need them on the other systems that I'm attempting to run the script. Correct me if I'm wrong.

Do I need a specific version of AutoIt to successfully compiled and run with Excel.au3? I'm using v3.2.12.1 and SciTE Version 1.76 Mar 30 2008 21:05:14.

I've unzipped Locodarwin's Excel.zip into my C:\Program Files\AutoIt3\Include directory and also tried it in the same directory of my script. Please let me know if this needs to be in a specific location.

Thank You in advance for your time and help with this.

Link to comment
Share on other sites

The problem is that once I compile the script and execute the exe on another system, it errors stating that it cannot open Excel.au3 which I've included in the beginning of the script with #include <Excel.au3>. My understanding is that once compiled, all include function should be included and I won't need them on the other systems that I'm attempting to run the script. Correct me if I'm wrong.

A compiled script is an .exe file, and it does not look for any .au3 files because the contents of #include files are already encoded inside the .exe file. If you took the .au3 script file to another computer that had AutoIt installed on it, then THAT computer's AutoIt3.exe will look for the #include file in that script. In short, it sounds to me like you moved the .au3 file to the other computer instead of the .exe file after compiling.

Do I need a specific version of AutoIt to successfully compiled and run with Excel.au3? I'm using v3.2.12.1 and SciTE Version 1.76 Mar 30 2008 21:05:14.

I've unzipped Locodarwin's Excel.zip into my C:\Program Files\AutoIt3\Include directory and also tried it in the same directory of my script. Please let me know if this needs to be in a specific location.

The version of Locodarwin's ExcelCOM_UDF.au3 that was included in the AutoIt distribution as Excel.au3 comes with Betas 3.2.13.4 and later. Since it is not included with the current production version 3.2.12.1, it would usually be found in ...\AutoIt3\Beta\Include, not the production Include directory.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

A compiled script is an .exe file, and it does not look for any .au3 files because the contents of #include files are already encoded inside the .exe file. If you took the .au3 script file to another computer that had AutoIt installed on it, then THAT computer's AutoIt3.exe will look for the #include file in that script. In short, it sounds to me like you moved the .au3 file to the other computer instead of the .exe file after compiling.

I've tried executing the .exe itself and running the .au3 file in AutoIt to see where it is erroring.

The version of Locodarwin's ExcelCOM_UDF.au3 that was included in the AutoIt distribution as Excel.au3 comes with Betas 3.2.13.4 and later. Since it is not included with the current production version 3.2.12.1, it would usually be found in ...\AutoIt3\Beta\Include, not the production Include directory.

:P

I'll install the betas 3.2.13.4 and see if the problem still occurs. Thanks for the quick reply PsaltyDS.

Link to comment
Share on other sites

Okay - still having a problem. Maybe I'm not understanding this correctly.

Here's what I've done.

1. Reinstalled AutoIt v3.2.12.1.

2. Installed Autoit-v3.2.13.7-beta-setup.exe

3. Installed SciTE4AutoIt3

My script is basically as follows:

; Generate the list of files to be used from excel file

$sFilePath = "C:\whatever.xls"

Local $oExcel = _ExcelBookOpen($sFilePath, 1)

Dim $fileArray[3]

$sizeofarray = UBound($fileArray)

For $i = 0 To UBound($fileArray)

$sCellValue = _ExcelReadCell($oExcel, $i, 1)

_ArrayPush($fileArray, $sCellValue)

Next

_ExcelBookClose($oExcel, 0)

Compiles and runs find on the machine that I'm working on.

I then compile this (Ctrl+F7), specifying it to compile using Beta: Ver:3.2.13.7. I copy the .exe file to another machine and execute it. Problem is that the array is not created. When I attempt to use the variable later it claims that its undeclared.

Please let me know what I'm doing incorrectly.

Thanks

Link to comment
Share on other sites

Okay - still having a problem. Maybe I'm not understanding this correctly.

Here's what I've done.

1. Reinstalled AutoIt v3.2.12.1.

2. Installed Autoit-v3.2.13.7-beta-setup.exe

3. Installed SciTE4AutoIt3

My script is basically as follows:

; Generate the list of files to be used from excel file

$sFilePath = "C:\whatever.xls"

Local $oExcel = _ExcelBookOpen($sFilePath, 1)

Dim $fileArray[3]

$sizeofarray = UBound($fileArray)

For $i = 0 To UBound($fileArray)

$sCellValue = _ExcelReadCell($oExcel, $i, 1)

_ArrayPush($fileArray, $sCellValue)

Next

_ExcelBookClose($oExcel, 0)

Compiles and runs find on the machine that I'm working on.

I then compile this (Ctrl+F7), specifying it to compile using Beta: Ver:3.2.13.7. I copy the .exe file to another machine and execute it. Problem is that the array is not created. When I attempt to use the variable later it claims that its undeclared.

Please let me know what I'm doing incorrectly.

Thanks

You don't show the includes at the top, and your For/Next loop iteration is bad. Try this:
#include <Excel.au3>
#include <Array.au3>

; Generate the list of files to be used from excel file
$sFilePath = "C:\whatever.xls"
If Not FileExists($sFilePath) Then MsgBox(16, "Error", "File not found:  " & $sFilePath)

Local $oExcel = _ExcelBookOpen($sFilePath, 1)
If @error Then MsgBox(16, "Error", "Error in _ExcelBookOpen(), @error = " & @error)

Dim $fileArray[3]
$sizeofarray = UBound($fileArray)

For $i = 0 To UBound($fileArray) - 1; <==== The "- 1" was missing here, would cause error
    $sCellValue = _ExcelReadCell($oExcel, $i, 1)
    If Not _ArrayPush($fileArray, $sCellValue) Then MsgBox(16, "Error", "Error pushing to stack, @error = " & @error)
Next
_ExcelBookClose($oExcel, 0)

_ArrayDisplay($fileArray, "$fileArray")

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You don't show the includes at the top, and your For/Next loop iteration is bad. Try this:

#include <Excel.au3>
#include <Array.au3>

; Generate the list of files to be used from excel file
$sFilePath = "C:\whatever.xls"
If Not FileExists($sFilePath) Then MsgBox(16, "Error", "File not found:  " & $sFilePath)

Local $oExcel = _ExcelBookOpen($sFilePath, 1)
If @error Then MsgBox(16, "Error", "Error in _ExcelBookOpen(), @error = " & @error)

Dim $fileArray[3]
$sizeofarray = UBound($fileArray)

For $i = 0 To UBound($fileArray) - 1; <==== The "- 1" was missing here, would cause error
    $sCellValue = _ExcelReadCell($oExcel, $i, 1)
    If Not _ArrayPush($fileArray, $sCellValue) Then MsgBox(16, "Error", "Error pushing to stack, @error = " & @error)
Next
_ExcelBookClose($oExcel, 0)

_ArrayDisplay($fileArray, "$fileArray")

:P

Thanks for the quick reply again PsaltyDS!!! I did have the includes at the top, but as you've mentioned, my loop was bad. Odd that it worked on the machine I was working on. Awesome!!! Time to try out other things.

Edited by bandor
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...