Formatting the contents of a bookmark as a numbered list

G

Guest

Hello,

I have a protected form that reads data from an external file into a field.
When it is in the form, I would like the data from the file to be formatted
as a numbered list.

The problem that I encounter is that the first item in the list will be
preceded by the appropriate list number, but none of the other lines have
any numbers. If I edit the field after the data has been read, new line
numbers will appear when I start a new line (i.e., press ENTER), but the
pre-existing lines as still without numbers.

Here is what I have. This code executes when entering a field.

Sub UpdateField()
Dim ReadLabel As Variant, ReadData As Variant, CurrentBookmark As Range
Set CurrentBookmark = ActiveDocument.Bookmarks(Selection.Bookmarks_
(Selection.Bookmarks.Count)).Range

' Open the file and read until the data label matches the bookmark name then
read the next piece of data and assign it to the bookmark
Open "C:\My documents\Summary.txt" For Input As #1
Do Until ReadLabel = Selection.Bookmarks(Selection.Bookmarks.Count).Name
Input #1, ReadLabel
Loop
Input #1, ReadData
Close #1
ActiveDocument.FormFields(Selection.Bookmarks_
(Selection.Bookmarks.Count).Name).Result = ReadData
End If

' Format the bookmark as a numbered list
CurrentBookmark.Fields(1).Result.Select
CurrentBookmark.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries_
(wdNumberGallery).ListTemplates(1), _
ContinuePreviousList:=False, ApplyTo:=wdListApplyToSelection
End Sub


The "Summary.txt" file may look like this:

"Apple","red<CR>delicious<CR>juicy","Lemon","yellow<CR>sour"

I would like the output to look like this:

(In the "Apple" bookmark)
1. red
2. delicious
3. juicy

(In the "Lemon" bookmark)
1. yellow
2. sour

What am I doing wrong?

-Brian
 
H

Harold Kless

Hi Brian,
If I'm reading this correctly you're adding text to formfields in a protect
form.
We can't format a list within a formfield to be numbered.
If you are inserting the text into the document, then your code should work
but you will have to unprotect the document to insert the text then
reprotect it when completed.

--
Harold Kless, MCSD
Support Professional
Microsoft Technical Support for Business Applications
(e-mail address removed)

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
 
G

Guest

Maybe I'm not explaining myself clearly. For a more "boiled down"
example... I can make a form with a single text box in it. I have this
macro

Sub UpdateField()
Set CurrentBookmark = ActiveDocument.Bookmarks(Selection.Bookmarks _
(Selection.Bookmarks.Count)).Range
CurrentBookmark.Fields(1).Result.Select
CurrentBookmark.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries_
(wdNumberGallery).ListTemplates(1), ContinuePreviousList:=False,
_
ApplyTo:=wdListApplyToSelection
End Sub

run on entry into the text box. Then I protect the form and save it as a
template. When I open a new document based on that template, the text that
I enter will be formatted in a numbered list.

My problem seems to arise when I read a string from an external file to use
to fill the text box. If the external file looks like this

"apples<CR>oranges<CR>pears"

My output looks like

1. apples
oranges
pears

instead of

1. apples
2. oranges
3. pears

Thanks for your interest in my question.

-Brian
 
K

Keith Miller

You need to convert your carriage returns to paragraph marks. Turn on non-printing characters &
take a look. Numbered format needs a paragraph mark to increment.

Keith
 
G

Guest

Is the paragraph mark assigned to a particular ascii code (or combination of
codes)? I assume in my external file, the list items are simply separated
by a carriage return (13). I didn't do a hex dump or anything, so it may be
a linefeed for all I know, but I tend to doubt it.

-Brian
 
G

Guest

It's working. For those who may be interested, I simply replaced Chr$(13)
with "^p" in the selected bookmark then applied the numbered list
formatting. Thanks for some direction, Keith. I'm still curious as to what
the ASCII code (or sequence) is for "^p".

Sub UpdateField()
Set CurrentBookmark = ActiveDocument.Bookmarks(Selection.Bookmarks _
(Selection.Bookmarks.Count)).Range
ActiveDocument.Unprotect
CurrentBookmark.Fields(1).Result.Select
Selection.Find.Execute FindText:=Chr$(13), ReplaceWith:="^p", _
Replace:=wdReplaceAll
CurrentBookmark.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries_
(wdNumberGallery).ListTemplates(1),
ContinuePreviousList:=False,_
ApplyTo:=wdListApplyToSelection
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub

-Brian
 

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