Page 1 of 1 1
Topic Options
#91665 - 2003-03-08 01:57 AM Man, Do I feel stupid - Excel
Cuervo Offline
Fresh Scripter

Registered: 2003-03-08
Posts: 14
Loc: Tampa, FL
I have a more complicated application, but will present a simplified example that should get me going... I'm extremely comfortable with scripting (and KiXtart in particular), but I'm totally lost on this COM stuff. Please forgive the TEMPORARY ignorance. ;-)
What I want to do is open an existing Excel spreadsheet and modify certain lines if certain text is found. For example, given an Excel file that consists of:

Server Package Status
S00010001 Package1 Success
S00020001 Package2 Success
S00030001 package2 Failed

I want to call a script that looks for "$Server", and changes that line so that the background is grey and the font is "srike-through." I think my main hangup is the Find method, but I've been unable to find any good examples. The test code I'm using is:

$Dollar = CHR(36)
$Server = "S00030001"
$oXL = CreateObject("EXCEL.application")
if @error = 0
$oXL.Visible = 1
$rc = $oXL.Workbooks.Open(c:\junk\packages.xls)
$Findit = $oXL.Range("A1:A500").Find(What:="$Server")
?"$$FindIt=$FindIt"
$FirstAddress = $FindIt.Address
?"$$FirstAddress=$FirstAddress"
$Index = INSTRREV($FirstAddress,"$Dollar")
?"$$Index=$Index"
$EndAddress = RIGHT($FirstAddress,LEN($FirstAddress)-$Index)
$StrikeRow = "$FirstAddress:$$C$$$EndAddress"
?"$$StrikeRow=$StrikeRow"
$oXL.Range("$StrikeRow").Font.Strikethrough = 1
$oXL.Range("$StrikeRow").Interior.ColorIndex = 15
ENDIF

I know, but I'm just trying to get the gist of what I need to do & then I can apply it to the real task, wrap in error-checking, etc...

If anyone can give me a clue or point me to the right doc, I would definitely appreciate it! If anyone is interested, here's the REAL application I'm trying to throw together:

Fantasy Football! Gotta get ready, now! ;-) I create a cheatsheet on Excel every year. I also run my league and the draft. It's extremely difficult to do the draft & keep up with my own spreadsheet, so I thought I'd try to script a solution. I'd like to call the KiX script after every pick, passing in the player's name and team (and maybe the position). The script would then open my spreadsheet, hunt for a matching player, and use the strikethrough and color on that line. Then, when it's my turn to draft, I can instantly see who is still available! Okay, not exactly work-related, but if any of you play Fantasy Football, you know the seriousness of this task!!!

Any help would be met with my undying gratitude and I'll buy the first round if you're ever in Tampa! ;-)

Top
#91666 - 2003-03-08 01:58 AM Re: Man, Do I feel stupid - Excel
Cuervo Offline
Fresh Scripter

Registered: 2003-03-08
Posts: 14
Loc: Tampa, FL
Great, all my formatting got dropped. Trust me, I know how to indent! Sorry...
Top
#91667 - 2003-03-08 02:30 AM Re: Man, Do I feel stupid - Excel
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Welcome to the board.

You should use the [code] and [/code] UBB code around your code to keep your indentation.
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#91668 - 2003-03-08 02:32 AM Re: Man, Do I feel stupid - Excel
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I'm in Tampa... [Big Grin]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91669 - 2003-03-08 02:34 AM Re: Man, Do I feel stupid - Excel
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
wouldn't:
Find(What:="$Server")

need to be:
Find('What:="$Server"')

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/office97/html/output/F1/D3/S5A521.asp

[ 08. March 2003, 02:47: Message edited by: Radimus ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#91670 - 2003-03-08 03:03 AM Re: Man, Do I feel stupid - Excel
Cuervo Offline
Fresh Scripter

Registered: 2003-03-08
Posts: 14
Loc: Tampa, FL
Nope, didn't work... You're in the running for a free round, though!
Top
#91671 - 2003-03-08 03:04 AM Re: Man, Do I feel stupid - Excel
Cuervo Offline
Fresh Scripter

Registered: 2003-03-08
Posts: 14
Loc: Tampa, FL
Thanks, MCA, I'll make sure to use the tags next time I post!
Top
#91672 - 2003-03-08 03:14 AM Re: Man, Do I feel stupid - Excel
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

It is more a surprise, when you as new member understands how this board works.
Specially when it deals about UBB code tags.
Your questions are always welcome on this board. Not only the experiences of board
members are great, but also the responses on question are very fast.
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#91673 - 2003-03-08 03:40 PM Re: Man, Do I feel stupid - Excel
Cuervo Offline
Fresh Scripter

Registered: 2003-03-08
Posts: 14
Loc: Tampa, FL
The weird thing is that the code I posted above does change the color and uses the strike-through font, but the Find always returns cell A2. I would have expected it to either find my hard-coded value (S00030001) in cell A4, or not find anything and possibly use A1 (since there is no error-checking in the script.) Maybe the Find defaults to begin at A2, assuming there is a header row... Weird.

So, if anyone has a snippet of code that finds text in a range of cells, I'd love to learn from it!

Top
#91674 - 2003-03-08 03:51 PM Re: Man, Do I feel stupid - Excel
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I recommend changing this line:

$Findit = $oXL.Range("A1:A500").Find(What:="$Server")

to this:

$Findit = $oXL.Range("A1:A500").Find("$Server")

might get rid of the bulk of your problems.

Hope this helps,

-Shawn

Top
#91675 - 2003-03-08 06:07 PM Re: Man, Do I feel stupid - Excel
Cuervo Offline
Fresh Scripter

Registered: 2003-03-08
Posts: 14
Loc: Tampa, FL
WooHOOOO!!!! That did it, thanks!

If we can't use the "What:=" part though, how can we use the other options of Find, like Matchcase, etc...?

Maybe .Find("$Server", MatchCase=1)...

Nope. Didn't work. Oh well, that should be enough to get me going in the right direction. I certainly appreciate the help!

Top
#91676 - 2003-03-08 06:34 PM Re: Man, Do I feel stupid - Excel
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Kixtart doesn't support named arguments so they must be positional, heres the docs you'll want to use for the FIND method:

Excel Find Method

The trick is in finding the numeric values for enumerated constants (like xlNext and xlPrevious, etc). I usually fireup the EXCEL VBA EDITOR and start the OBJECT BROWSER - when you located the constant your looking for, its numeric value is reported along with the syntax for the enumeration.

In terms of the MATCHCASE parameter, luckily thats just a boolean true/false, and its the 7th parm in the find method. You can omit all the other parms before that but just using commas.

-Shawn

Top
#91677 - 2003-03-08 09:11 PM Re: Man, Do I feel stupid - Excel
Cuervo Offline
Fresh Scripter

Registered: 2003-03-08
Posts: 14
Loc: Tampa, FL
Excellent. I should be self-sufficient now, thanks!
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 823 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.066 seconds in which 0.027 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