Page 1 of 1 1
Topic Options
#179496 - 2007-08-21 11:37 AM Creating and saving an excel sheet does not "kill" excel
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Guy's,

This is my first stab at excel com and I have a question.
When I execute the code below (it uses some UDF's from the link) excel stays open and I'm unable to open the file for writing.
I tried things setting the three vars to 0 or null (empty) but excel is still running when I look at the task manager. What am I missing here?

 Code:
$excel = xlInstantiateApp() ;initiate excel
$workbook = xlNewBook($excel, 4) ;create excel file with 4 sheets.
$save = xlFile($excel, 1, "c:\testsheet.xls") ;save excel file


Lounge » RFC: xlLib - Library of MS Excel UDFs


Edited by Mart (2007-08-21 11:39 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#179499 - 2007-08-21 12:33 PM Re: Creating and saving an excel sheet does not "kill" excel [Re: Mart]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Hi Mart,

You saved your worksheet, but you haven't closed down excel. I haven't coded for excel yet, but maybe

$excel.quit

?

Regards,

Brad V

Top
#179502 - 2007-08-21 01:30 PM Re: Creating and saving an excel sheet does not "kill" excel [Re: Mart]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
You can also make it visible
$objExcel.Visible = -1
(-1 = True)

Top
#179504 - 2007-08-21 01:44 PM Re: Creating and saving an excel sheet does not "kill" excel [Re: Witto]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Brad,
You da man. I thought setting it to 0 or null would do the trick but it didn’t. $excel.quit works great.
Almost ashamed to say that with 2k3+ posts I just started using com a few weeks ago

Witto,
There is no need to make it visible (yet). But it's good to know that it is possible for stuff still to come in the future. For now I just need to create the workbook with x amount of sheets with the sheet(s) having a specific name.

 Code:
$excel = xlInstantiateApp() ;initiate excel
$workbook = xlNewBook($excel, 4) ;create excel file with 4 sheets.
$save = xlFile($excel, 1, "c:\testsheetnew1.xls") ;save excel file
$excel.quit


Edited by Mart (2007-08-21 01:46 PM)
Edit Reason: Added working code and ripped out a typo.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#179521 - 2007-08-21 04:03 PM Re: Creating and saving an excel sheet does not "kill" excel [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
You might find this UDF Library helpful.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#179523 - 2007-08-21 04:08 PM Re: Creating and saving an excel sheet does not "kill" excel [Re: Mart]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I use the visible as long as I am writing and debugging the script. I thought is was a good tip. But I agree on the fact if there is no need to make the workbook visible, it is a good idea to keep it in background and close it with .quit
Top
#179524 - 2007-08-21 04:09 PM Re: Creating and saving an excel sheet does not "kill" excel [Re: Glenn Barnas]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
That's the stuff I used. My link is the same as your link \:D
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#179525 - 2007-08-21 04:11 PM Re: Creating and saving an excel sheet does not "kill" excel [Re: Witto]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Originally Posted By: Witto
I use the visible as long as I am writing and debugging the script. I thought is was a good tip. But I agree on the fact if there is no need to make the workbook visible, it is a good idea to keep it in background and close it with .quit


Sure it's a good tip. Could have used it to find out what was going wrong with my script. Thanks for pointing it out.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#179537 - 2007-08-21 07:51 PM Re: Creating and saving an excel sheet does not "kill" excel [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Oh yeah - Duh! Should have finished my coffee, I guess.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#179541 - 2007-08-21 11:26 PM Re: Creating and saving an excel sheet does not "kill" excel [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hopefully your excel script doesn't run at the same time as the user is writing your new increased salaries.
as your quit line will kill that visible window too \:\)
or does it?
_________________________
!

download KiXnet

Top
#179551 - 2007-08-22 07:08 AM Re: Creating and saving an excel sheet does not "kill" excel [Re: Lonkero]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Luckily we don't do salaries in Excel and I just got mine for this month so I'm ok (for now) \:D
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#179552 - 2007-08-22 10:07 AM Re: Creating and saving an excel sheet does not "kill" excel [Re: Lonkero]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
 Originally Posted By: JOOEL

your quit line will kill that visible window too \:\)

Jooel,
Have you tried that? It does not.
Here is a simple script that you can run while you have another instance of Excel running:
;*************************************************************************
;  Script Name:  
;  Author:        Wim Rotty
;  Date:          22/08/2007
;  Description:   Open and close new workbook
;*************************************************************************

 
;Script Options
If Not @LOGONMODE
    Break On
Else
    Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
If @SCRIPTEXE = "KIX32.EXE"
    $RC = SetOption("WrapAtEOL", "On")
EndIf

;Declare variables
DIM
 
$objExcel

;Initialize variables
$objExcel = CreateObject("Excel.Application")
If @ERROR
    Exit @ERROR
EndIf

;Code
$RC = $objExcel.Workbooks.Add
$objExcel.Visible
 = -1
$RC = $objExcel.Quit

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1527 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.062 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org