Set list level number in MS Word with AppleScript

J

Jimmy_Vegas

Version: 2008
Operating System: Mac OS X 10.6 (Snow Leopard)
Processor: Intel

Hello All,
The script I'm writing gathers input from display dialogs then formats the information to be written into MS Word. The paragraph formatting changes throughout the document, and I'm using bookmarks to hold insertion points. Sometimes, an straight paragraph format gets inserted into a numbered list, and the numbering has to pick up again after that insertion.

In the code listed below, the paragraph needs to number 7 on the list. (This number changes based on other variables, else I would just hard code it.)

I've gone through the MS Word AppleScript dictionary and been to the developer area of MacTopia and can't figure this one out.

I've commented the problematic line in the code listed below. If anyone knows the syntax of this particular command, I would greatly appreciate any help.

Code
-------------------------

tell application "Microsoft Word"
activate

select bookmark "legal_07" of active document
tell paragraph format of selection to set style to style list number

-- here's the problematic line
tell list format of selection to set list level number to 7

tell font object of selection
set name to "Times New Roman"
set bold to true
set underline to true
set font size to 12
end tell
--tell paragraph format of selection to set alignment to align paragraph left
type text selection text var_lawcn01
make new bookmark at active document with properties {name:"legal_02", text object:text object of selection}
end tell

----------------------------
/Code

I've tried several variations on this and can't quite figure it out.

Any and all help is greatly appreciated.
 
J

John McGhie

Version: 2008
Operating System: Mac OS X 10.6 (Snow Leopard)
Processor: Intel

Hello All,
The script I'm writing gathers input from display dialogs then formats the
information to be written into MS Word. The paragraph formatting changes
throughout the document, and I'm using bookmarks to hold insertion points.
Sometimes, an straight paragraph format gets inserted into a numbered list,
and the numbering has to pick up again after that insertion.

In the code listed below, the paragraph needs to number 7 on the list. (This
number changes based on other variables, else I would just hard code it.)

I've gone through the MS Word AppleScript dictionary and been to the developer
area of MacTopia and can't figure this one out.

I've commented the problematic line in the code listed below. If anyone knows
the syntax of this particular command, I would greatly appreciate any help.

Code
-------------------------

tell application "Microsoft Word"
activate

select bookmark "legal_07" of active document
tell paragraph format of selection to set style to style list
number

-- here's the problematic line
tell list format of selection to set list level number to 7

tell font object of selection
set name to "Times New Roman"
set bold to true
set underline to true
set font size to 12
end tell
--tell paragraph format of selection to set alignment to align
paragraph left
type text selection text var_lawcn01
make new bookmark at active document with properties
{name:"legal_02", text object:text object of selection}
end tell

----------------------------
/Code

I've tried several variations on this and can't quite figure it out.

Any and all help is greatly appreciated.


Hmm...

I don't do AppleScript, so I can't quite understand what you are up to
there.

This is how I do it in Word 2004:

Sub RestartNumber()
With Selection.Paragraphs
If .Item(1).Range.ListFormat.ListTemplate Is Nothing Then End
With .Item(1).Range.ListFormat
.ApplyListTemplate .ListTemplate, False
End With
End With
End Sub

Sub ContinueNumber()
With Selection.Paragraphs
With .Item(1).Range.ListFormat
.ApplyListTemplate .ListTemplate, True
End With
End With
End Sub

Now, what is happening there is that in each case, I am returning the List
Template of the List Format from the Range of the first paragraph in the
selection.

I am then re-applying the same list template to the list format, with its
"continue" property set to either TRUE or FALSE.

The key to it is to return the actual list template in use and toggle it.

Reading your code, it appears you are setting the "List Level" property, not
the "Starts At" value. In other words, it would appear that your code is
changing the level of the paragraph in an outline list.

What they will do is detach the current paragraph from the List Style and
create an orphan.

If you create a style of type List in the document, and then define your
paragraph styles into the List Style, one paragraph style for each list
level, then it should just work.

Using an Outline list style, you should be able to insert interstitial
un-numbered paragraphs within the list without disturbing the numbering of
the following paragraphs.

As soon as you get into complex documentation such as yours, you must use
List Styles in conjunction with paragraph styles. It is the only way to get
the numbering stable.

Hope this helps

This email is my business email -- Please do not email me about forum
matters unless you intend to pay!

--

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410
+61 4 1209 1410, mailto:[email protected]
 
J

Jimmy_Vegas

Thank you, John. I'll see if I can incorporate that into my code. It seems like I'm just up against some simple syntax. If not, I may have another way to do it.
 
J

John McGhie

Thank you, John. I'll see if I can incorporate that into my code. It seems
like I'm just up against some simple syntax. If not, I may have another way to
do it.

Hi Jimmy:

No probs: I have had many rounds with this mechanism over the years. I can
confidently say that attacking it in code is not a good way to do this :)

Investigate creating a List style and a set of Paragraph styles: your
results will be a LOT more reliable, and other users won't stuff up your
documents when they edit them (well, not as much...)

Cheers

This email is my business email -- Please do not email me about forum
matters unless you intend to pay!

--

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410
+61 4 1209 1410, mailto:[email protected]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top