Here's a snippet of AS that I'm currently having trouble with:
make new standard inline horizontal line at the beginning of text object
of paragraph 15
set height of standard inline horizontal line 1 to 2.5
set color of standard inline horizontal line 1 to ({0, 0, 0} as
RGB color)
set no shade of horizontal line format of standard inline
horizontal line 1 to true
set alignment of horizontal line format of standard inline
horizontal line 1 to horizontal line align left
The problem I'm having is that I'm trying to set the color of the line
("set color....") and it isn't working.
I've also tried "fore color" and "back color" to no avail.
I've perused the Word 2004 AS reference, the Word 2008 AS dictionary,
any existing code I could find and tried googling for an answer, all to
no avail.
Anyone care to correct what likely is a silly mistake in syntax?
I'll give it a go. If you check the dictionary, you will see (and probably
have seen) that there is no 'color' property of standard inline horizontal
line, so of course it can't be set and that's why it's erroring. You
probably realize that. It also has no 'fore color' nor 'back color'
properties.
It does, however, have two promising, properties 'fill format' and 'line
format', each of which do have 'fore color' nor 'back color' properties.
When I made a new standard inline horizontal line, and then tried to get its
line format, the result was 'missing value', So probably that's not going to
be it. When I tried to get its fill format, however, I got a fully fledged
object, that already had a default fore color of {170, 170, 170} and a back
color of {255, 255, 255}. So that looked like a good bet, and it is. It
turns out that fore color of the fill format is the one you want.
A few pointers before we try it:
1) you should set a variable to the new line you make and then adjust that
variable, instead of always going back to standard inline horizontal line 1.
Aside from being heavy lifting and slower, always having to send a new
AppleEvent to fins line 1, it might not even *be* line 1.
2) The dictionary is incorrect when it refers to 'color' properties as being
of 'RGB color' class. It's actually using the Microsoft RGB values as in
VBA, which are all 256-based (0-255) whereas AppleScript's true 'RGB color'
class values are 65536-base (0-65535). Of course for {0,0,0} it makes no
difference, but for all other values it does. If you're translating a VBA
macro, just use the numbers you see there, but do NOT add 'as RGB color'. If
you are using pre-existing AppleScript values you got from some other place,
you can get the square root ( ^ .5) of each of the three values to get the
Microsoft-equivalent and use those values.
3) Always refer to the paragraph of the 'active document' or some named
document, or you'll run into trouble some day.
So:
tell application "Microsoft Word"
set hzLine to make new standard inline horizontal line at the beginning
of text object of paragraph 15 of active document
set height of hzLine to 2.5
set fore color of fill format of hzLine to {0, 0, 0}
set no shade of horizontal line format of hzLine to true
set alignment of horizontal line format of hzLine to horizontal line
align left
end tell
One more tip: You could make it neater by 'telling' the object after
creating it (like With in VBA), instead of having to say 'of hzLine' in
every line, but in this case you'll need to say 'its' for most of the
properties, so maybe it's not such an advantage:
tell application "Microsoft Word"
set hzLine to make new standard inline horizontal line at the beginning
of text object of paragraph 15 of active document
tell hzLine
set height to 2.5
set fore color of its fill format to {0, 0, 0}
set no shade of its horizontal line format to true
set alignment of its horizontal line format to horizontal line align
left
end tell
end tell
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <
http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <
http://macscripter.net/scriptbuilders/>
Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.
PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.