Jump to content

Recommended Posts

Posted

Hi,

I'm trying to do some work in excel with a script. Having a "handle" problem. I'm using Excel.au3 package from locodarwin.

When using _ExcelBookOpen it says if successful it should return the new object identifier. I suspect this to be a number or something.

My code is below. When running it, the workbook opens, then closes successfully, but if I try to put the return value, I get nothing. What am I missing?

$oExcel = _ExcelBookOpen($excelFilePath)

MsgBox(1,"Excel",$oExcel)

clipput($oExcel)
_ExcelBookClose($oExcel)
Posted (edited)

Hi,

I'm trying to do some work in excel with a script. Having a "handle" problem. I'm using Excel.au3 package from locodarwin.

When using _ExcelBookOpen it says if successful it should return the new object identifier. I suspect this to be a number or something.

My code is below. When running it, the workbook opens, then closes successfully, but if I try to put the return value, I get nothing. What am I missing?

$oExcel = _ExcelBookOpen($excelFilePath)

MsgBox(1,"Excel",$oExcel)

clipput($oExcel)
_ExcelBookClose($oExcel)
What is value of $excelFilePath?Use @error to see if you can create the Excel COM object. Edited by Andreik
Posted

What is value of $excelFilePath?Use @error to see if you can create the Excel COM object.

Yes, it's creating just fine I believe. I mean the file in that path is opening. and when I tell it to close via script, it closes too, I just can't see any "handle" for it. I'm beginning to wonder if I'm supposed to be able to.

?

  • 1 month later...
Posted

Below is an idea of what I'm trying to do.

#include <GuiButton.au3>
#include <GUIConstants.au3>
#include <Excel.au3>

$Test = GUICreate("Show / Hide", 305, 115, 320, 300)
$Button0 = GUICtrlCreateButton("Open", 25, 70, 130, 30)
$Button1 = GUICtrlCreateButton("Show", 155, 70, 130, 30)
$Button2 = GUICtrlCreateButton("Hide", 155, 70, 130, 30)
GUICtrlSetState($Button2 , $gui_Hide)
$Input1 = GUICtrlCreateInput("", 25, 40, 210, 20)
$Button3 = GUICtrlCreateButton("", 240, 25, 30,30, $BS_ICON)
_GUICtrlButton_SetImage($Button3, "shell32.dll", 55, True)
$Label1 = GUICtrlCreateLabel("Enter in the path to your excel file.", 25, 15, 215, 20)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button3
            $var = FileOpenDialog("Choose a file.",@ScriptDir&"", "Excel (*.csv)|ALL (*.*)")
            GUICtrlSetData($Input1,$var)
        Case $Button0
            $oExcel = _ExcelBookOpen(GUICtrlRead($Input1),0); 0 = NOT Visible | 1 = Visible
        Case $Button1
            
        ;I need it to show the Excel window.
            
            GUICtrlSetState($Button1 , $gui_Hide)
            GUICtrlSetState($Button2 , $gui_Show)
        Case $Button2
            
        ;I need it to hide the Excel window.
            
            GUICtrlSetState($Button1 , $gui_Show)
            GUICtrlSetState($Button2 , $gui_Hide)
    EndSwitch
WEnd
Posted

Hi,

I'm trying to do some work in excel with a script. Having a "handle" problem. I'm using Excel.au3 package from locodarwin.

When using _ExcelBookOpen it says if successful it should return the new object identifier. I suspect this to be a number or something.

My code is below. When running it, the workbook opens, then closes successfully, but if I try to put the return value, I get nothing. What am I missing?

$oExcel = _ExcelBookOpen($excelFilePath)

MsgBox(1,"Excel",$oExcel)

clipput($oExcel)
_ExcelBookClose($oExcel)
$oExcel is an object, not a handle, so it can't be displayed directly as a string (or copied to the clipboard as far as I know).

Try this instead:

#include <Excel.au3>

$excelFilePath = "C:\Temp\Test.xls"
$oExcel = _ExcelBookOpen($excelFilePath)
$sExcel = ObjName($oExcel); Retrieve object name
MsgBox(1,"Excel","$oExcel object is: " & $sExcel)
_ExcelBookClose($oExcel)

:mellow:

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

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...