Page 1 of 1 1
Topic Options
#39476 - 2003-04-23 07:56 PM Reading from an Excel File
Tomalok Offline
Fresh Scripter

Registered: 2003-04-23
Posts: 6
Loc: Berne, IN
I am trying to write a script to read from cells C3 and C6 in an Excel file. If the event reads "overdue" then have a message box come up and tell the user they need to do a new machine set up. I am having trouble finding the right syntax to set this up. This is my first Kixtart script and so far, no good... Can anyone help?
Top
#39477 - 2003-04-23 08:06 PM Re: Reading from an Excel File
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Search the KiXtart BBS for 'read excel' as this has already been discussed and sample scripts have been provided. The most likely source for these scripts will be the COM Forum.

[ 23. April 2003, 20:09: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#39478 - 2003-04-23 08:10 PM Re: Reading from an Excel File
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Tomalok,

Welcome to the board!

Have a look at -

READEXCEL() - Read an Excel Spreadsheet and return results

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#39479 - 2003-04-25 05:50 PM Re: Reading from an Excel File
Tomalok Offline
Fresh Scripter

Registered: 2003-04-23
Posts: 6
Loc: Berne, IN
I have the script reading the file, but it will not close Excel automatically. Is there a special function to close the file without asking for it to save if there is not changes to the file??

Thanks

Top
#39480 - 2003-04-25 05:58 PM Re: Reading from an Excel File
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
might try:

code:
 $xls.UserControl = 1
$= $xls.quit


Top
#39481 - 2003-04-25 06:02 PM Re: Reading from an Excel File
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The UDF itself does not contain code to close the Excel. I think that should be part of the UDF itself as it also opens Excel.
_________________________
There are two types of vessels, submarines and targets.

Top
#39482 - 2003-04-25 06:27 PM Re: Reading from an Excel File
Tomalok Offline
Fresh Scripter

Registered: 2003-04-23
Posts: 6
Loc: Berne, IN
No luck so far. Here is my code. This is my first venture using KixTart in many years
code:
   break on

$objXL = CreateObject("EXCEL.application")

if @error = 0


$rc = $objXL.Workbooks.
$objWorkbook = $objXL.Workbooks.Open("c:\WeldFlag.xls")
$objWorksheet = $objWorkbooks.ActiveSheet

$objCell = $objWorksheet.Range("c3")

If $objCell.Value = "overdue"
$objXL.Visible = 1
$Selection = MessageBox ("Please do a new Setup on Welder 601", "OVERDUE SETUP ON 601", 36)
If $Selection = 6
? "Enter New Setup Date on Worksheet and Anstat"
sleep 4
Endif
Endif
break off
$Selection = MessageBox ("NO Setup NEEDED on Welder 601", "Good SetUp ON 601", 64)



$objXL.Quit
$objXL = 0

:end


Top
#39483 - 2003-04-25 06:33 PM Re: Reading from an Excel File
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
first, please it's KiX.
thus KiXtart...

anyway, at first glance I simply see you missing one endif.

mm...
what comes to not closing...
does it even work with quit right after you have created it?
you can also try (with it, just before):
$objWorkbook.close()

to close the workbook before shutting down the app...

[edit]
reading from your next reply that it actually works.
it just misses that force thingie...

can find it from office's scripting manual...

[ 25. April 2003, 18:44: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#39484 - 2003-04-25 06:41 PM Re: Reading from an Excel File
Tomalok Offline
Fresh Scripter

Registered: 2003-04-23
Posts: 6
Loc: Berne, IN
Aded extra endif and $objWorkbook.close(), but it still comes up with a box asking if I want to save the file. I am wanting it to run in the background with no user intervention if no "Setup" is needed. And since it still asks to save the file, it does not yet work correctly.

Jeff

Top
#39485 - 2003-04-25 06:50 PM Re: Reading from an Excel File
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Try something on the order of
code:
$objXL.Workbooks.Save
$objXL.Workbooks.close
$objXL.quit

_________________________
There are two types of vessels, submarines and targets.

Top
#39486 - 2003-04-25 06:53 PM Re: Reading from an Excel File
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Have you tried to STFW?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrCreatingSavingOpeningClosingWorkbookObjects.asp

quote:
You use a Workbook object's Close method to close an open workbook. To specify whether pending changes to the workbook should be saved before the object is closed, you use the SaveChanges argument. If the SaveChanges argument is omitted, the user is prompted to save pending changes. You can also use the Close method of the Workbooks object to close all open workbooks. If there are unsaved changes to any open workbook when this method is used, the user is prompted to save changes. If the user clicks Cancel in this Save dialog box, an error occurs. You can suppress this Save dialog box by setting the Application object's DisplayAlerts property to False before executing the Close method. When you use the Workbooks object's Close method in this manner, any unsaved changes to open workbooks are lost. After the Close method has run, remember to set the DisplayAlerts property to True.


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#39487 - 2003-04-25 06:59 PM Re: Reading from an Excel File
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
To avoid the save dialog, use:
code:
$oXl.DisplayAlerts = 0
$RC = $oXl.Quit

-Erik

You might get som more idaes from my post:
Collection of UDF's for Excel

Sorry i have not made this ready for the UDF-forum. Anyone is welcome

[ 25. April 2003, 19:16: Message edited by: kholm ]

Top
#39488 - 2003-04-25 07:53 PM Re: Reading from an Excel File
Tomalok Offline
Fresh Scripter

Registered: 2003-04-23
Posts: 6
Loc: Berne, IN
Erik,

IT WORKED! I changed your syntax to match mine (oXl to objXL)

To: LLigetf, What is SRFW????

Thanks

[Big Grin]

Top
#39489 - 2003-04-25 07:55 PM Re: Reading from an Excel File
Tomalok Offline
Fresh Scripter

Registered: 2003-04-23
Posts: 6
Loc: Berne, IN
LLigetfa

Sorry about my poor typing, I was overcome with joy in that it finally worked. What is STFW?

[Confused]

Top
#39490 - 2003-04-25 07:57 PM Re: Reading from an Excel File
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well, there is the more common translation... but I prefer the one in my sig.

Search The Free Web
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

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 1114 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.065 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

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