Re: XL - Certain text to bold?
Re: XL - Certain text to bold?
- Subject: Re: XL - Certain text to bold?
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 16 Nov 2002 09:23:56 -0800
Just to let you know: I forwarded your post, Kai, to the Excel people, and
their AppleScript expert just got back to me confirming the bugs. She asked
me to pass on thanks for drawing it to their attention. I think you can
expect it to be fixed in a later release, although that wasn't spelled out.
--
Paul Berkowitz
>
From: Kai Edwards <email@hidden>
>
Date: Tue, 12 Nov 2002 09:00:40 +0000
>
To: <email@hidden>
>
Subject: Re: XL - Certain text to bold?
>
>
on Sun, 10 Nov 2002 15:29:24 -0600, Jay Young <email@hidden> wrote:
>
>
> Does anyone know if it's possible to change the text style only on
>
> certain words in a cell in Excel with AppleScript?
>
>
>
> For example, let's say in cell A1 I have this:
>
>
>
> The sky is very blue today.
>
>
>
> I would like to leave all the text the same, but I'd like to make 'sky'
>
> bold. So I've tried running this code:
>
>
>
> --------------------------
>
> tell application "Microsoft Excel"
>
> set Cell "r1c1"'s Characters 5 thru 7's Font's FontStyle to "bold"
>
> end tell
>
> ---------------------------
>
>
>
> But instead of making 'sky' bold, it makes every word bold.
>
>
>
> I could make a Macro with VBA and then have AppleScript run that, but
>
> does anyone know if there's another way?
>
>
OMM, this behaviour looks a mite suspicious to me, Jay.
>
>
It looks like AS/Excel _should_ be able to do what you're asking. All the
>
necessary terms are available to apply formatting to specified characters
>
within a cell. However, any formatting commands, instead of being applied
>
selectively to the specified characters, format the entire cell.
>
>
Even if one tries to set the style of all characters in the cell, like
>
this...
>
>
----------------------------------------------------
>
tell application "Microsoft Excel"
>
set Cell "R1C1"'s Characters 1 thru 4's Font's FontStyle to "Regular"
>
set Cell "R1C1"'s Characters 5 thru 7's Font's FontStyle to "Bold"
>
set Cell "R1C1"'s Characters 8 thru 27's Font's FontStyle to "Regular"
>
end tell
>
----------------------------------------------------
>
>
...the entire cell is formatted first as regular, then as bold - and finally
>
as regular again.
>
>
I'm no VB expert, but your approach works well enough using a VB macro:
>
>
----------------------------------------------------
>
Sub FormatChars()
>
With Range("A1").Characters(Start:=5, Length:=3).Font
>
.FontStyle = "Bold"
>
End With
>
End Sub
>
----------------------------------------------------
>
>
...but only when called from within Excel. When the macro is called from AS
>
like this:
>
>
----------------------------------------------------
>
tell application "Microsoft Excel" to Evaluate "Workbook1!FormatChars()"
>
----------------------------------------------------
>
>
...characters 5 thru 27 ("sky is very blue today.") are formatted as bold.
>
>
>
If one tries to mimic the step-by-step approach used by the recording
>
process, like this:
>
>
----------------------------------------------------
>
Sub FormatChars()
>
With Range("A1").Characters(Start:=1, Length:=4).Font
>
.FontStyle = "Regular"
>
End With
>
With Range("A1").Characters(Start:=5, Length:=3).Font
>
.FontStyle = "Bold"
>
End With
>
With Range("A1").Characters(Start:=8, Length:=20).Font
>
.FontStyle = "Regular"
>
End With
>
End Sub
>
----------------------------------------------------
>
>
...the macro also works as expected when called from within Excel. From AS,
>
however, characters 5 thru 7 _and_ characters 21 thru 27 ("sky" & " today.")
>
are formatted as bold. (It's almost as if 'Length' might be counted from the
>
string's first character - rather than from the value given by 'Start' in
>
each case.)
>
>
However, by ignoring any reference to 'Length' - and modifying the code to
>
this:
>
>
----------------------------------------------------
>
Sub FormatChars()
>
With Range("A1").Characters(Start:=1).Font
>
.FontStyle = "Regular"
>
End With
>
With Range("A1").Characters(Start:=5).Font
>
.FontStyle = "Bold"
>
End With
>
With Range("A1").Characters(Start:=8).Font
>
.FontStyle = "Regular"
>
End With
>
End Sub
>
----------------------------------------------------
>
>
...the macro works as intended - whether called from Excel or AS.
>
>
So, while the results within Excel seem to be pretty consistent, the
>
responses to AS seem somewhat... quirky.
>
>
Since I can't come up with a logical explanation for this behaviour, my
>
guess is that there's a bug in there somewhere. If so, I wonder whether it's
>
a documented one? (Or is this just OMM?)
>
>
Anyone?
>
>
Kai
>
>
--
>
email@hidden
>
email@hidden
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.