Page 1 of 1 1
Topic Options
#202330 - 2011-05-24 11:40 PM Close excel when done
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
I have a script that opens excel and I need to be able to close at the end. So far what I have is not working. We are currently using MS Office 2003 (2007 has some issues with e-mailing documents).
The below is the kix script.

?"create object"
$app = CreateObject("Excel.Application")
;$app.visible = 1
?"create wbs"
;Create the Workbooks object
$file = "Y:\medicomm.xls"
$wbs=$app.Workbooks.Open($file)


;$app.Range("A1:H1").insert

?"range"
$app.Range("A1").Entirecolumn.NumberFormat = "mm/dd/yy"
$app.Range("I1").Entirecolumn.NumberFormat = "mm/dd/yy"
$app.Range("Q1").Entirecolumn.NumberFormat = "mm/dd/yy"
$app.Range("T1:W1").Entirecolumn.NumberFormat = "$#,##0.00"

$app.Range("X1:Y1").EntireColumn.Delete
$app.Range("A1:W1").EntireColumn.Autofit


copy "y:\medicomm.xls" "y:\medicomm-@year-@monthno-@mdayno.xls" /y
$filename = "y:\medicomm-@year-@monthno-@mdayno.xls"

$app.ActiveWorkbook.SaveAs("$filename")


;IMPORTANT--YOU MUST CLOSE THE WORKBOOKS OBJECT OR ELSE
; THE EXCEL PROCESS WILL NOT TERMINATE!!!
$wbs.Close

;Destroy the Worksheet, Workbooks, and Application objects
$wbs = 0
$app = 0

Top
#202331 - 2011-05-25 12:09 AM Re: Close excel when done [Re: Karon]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
This seems to work fine for me. I dont quite understand why you are making a copy of y:\medicomm.xls to y:\medicomm-@year-@monthno-@mdayno.xls and then right afterwards saving the edited file over it, so I just commented it out. The /y switch is also not known to me in kix. Also got rid of the console by adding a few $nul= lines. But anyway give this a shot.

 Code:
$app = CreateObject("Excel.Application")
$app.visible = 0

$file = "Y:\medicomm.xls"
$wbs=$app.Workbooks.Open($file)

;$app.Range("A1:H1").insert

$app.Range("A1").Entirecolumn.NumberFormat = "mm/dd/yy"
$app.Range("I1").Entirecolumn.NumberFormat = "mm/dd/yy"
$app.Range("Q1").Entirecolumn.NumberFormat = "mm/dd/yy"
$app.Range("T1:W1").Entirecolumn.NumberFormat = "$#,##0.00"

$nul = $app.Range("X1:Y1").EntireColumn.Delete
$nul = $app.Range("A1:W1").EntireColumn.Autofit

$filename = "Y:\medicomm-"+@year+"-"+@monthno+"-"+@mdayno+".xls"

$nul = $app.ActiveWorkbook.SaveAs($filename)

$nul = $wbs.Close
$wbs = 0
$app = 0

Top
#202334 - 2011-05-25 02:29 PM Re: Close excel when done [Re: ShaneEP]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
That did it! I was not the original author of the script, so I have no idea about the redundancy. Thanks! File created and excel closed!!
Top
#202336 - 2011-05-25 04:48 PM Re: Close excel when done [Re: Karon]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Great!
Top
Page 1 of 1 1


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

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.064 seconds in which 0.034 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