Thank you Steve and Peter,
The Text entries are listed sequentially in the first column of a
table, which table is part of a document which is opened by my
userform using
Set sourcedoc = Documents.Open(FileName:="C:\My
Documents\MacroName.doc")
A second column of the table provides a key "MacroName", which is
searched to access the appropriate row in the table, where something
like "[PetOwner] would like to have [PetsName] returned by
[DayOfTheWeek]" is found in the second "InsertText" column , and
eventually used as an insertion into the ActiveDocument at the
insertion point by a UserForm that is well under control at this
point.
Based on your previous replies, and after thinking about it over the
weekend, I think what I really need is some code to search the table
row by row, and in each instance where there is an
"[anythingwhatever]" in the InsertText cell, to set a range therein to
place a hidden "enclosed" bookmark that embraces the entire
"[anythingwhatever]" (while leaving the "[anythingwhatever]" in place
and visible) and then continuing in the same InsertText cell,
doing the same thing until it gets to the end of the text in
InsertText cell for that row. If I had that, I could go forward. I
understand the need to check for a pre-existing bookmark with the same
name before assigning a name.
So, something of the order:
For each
"[" in InsertText followed by a complementary "]" ...
set an enclosing bookmark named "BookMarkName"
(previously checked for to prevent duplicates)
that encloses every character from the "[" to the "]" and
Then
go on doing that until to the end of that InsertText cell.
Next RowInTheTable
I think I can manage what goes on outside this routine ... and to
describe it further would, I think, add some unnecessary confusion to
the picture.
(At least, I think it would ... otherwise I'll be coming to the door
again, with my outstretched hand. Please bear with me and get me to
this point.)
TIA
Sophia
G'day Sophia <
[email protected]>,
myrange.bookmarks.add aUniqueName, myrange
aUniqueName is just aUniqueStem appended with an incrementing number.
Before you start you just check for the existance of a bookmark with
the proposed start UniqueName and increment until you dont find one
While ActiveDocument.Bookmarks.Exists(aUniqueStem & format(k))
k=k+1
wend
Steve Hudson - Word Heretic Sydney Australia
Tricky stuff with Word or words
Email: steve at wordheretic.com
Sophia reckoned:
Peter,
Sorry to have given you only part of the picture. We actually have
*hundreds* of these text entries now ... all in the format I described
(with the square brackets as shown) and more are coming to us from
other sources, which may or may not have originated in Word.
I was thinking that rather than to go back and edit each one of those
hundreds (by adding Word bookmarks), and accomodate the new arrivals,
we might be able to plug them as is, and from the insertion point,
locate the enclosing brackets programmatically, and add enclosing
bookmarks between the pairs of brackets.
I've already put together an array that provides the starting and
ending positions of the brackets in the insertion ... so I know where
they are with reference to the insertionpoint. What I don't know, and
have been unable to discover, is the code for "between this starting
bracket and that ending bracket ... create and name a bookmark that
will be used later to accept the data in the fields in the form."
Could you help me with that?
TIA
Hi Sophia
I'm not sure why you're trying to create the boookmarks programatically (I
may have missed your point here!). Normally you create the boilerplate text
in your template and manually add bookmarks where you want to insert variable
text (say entered through a UserForm) into your document.
If this is what you're trying to do check out the following links:
http://word.mvps.org/FAQs/Userforms/index.htm
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
the second link also contains code on how to get text entered into a UserForm
control into the bookmark in your document.
You can of course create bookmarks programatically, but the trick of course
is knowing where in the document you want to create them!
If you need more info, or I missed the mark please post again.
HTH + Cheers - Peter
4ax.com:
Hello,
If I have an item such as:
"[PetOwner] would like to have [PetsName] returned by [DayOfTheWeek]"
in a document.
What is the code to create a set of "enclosing" bookmarks B1, B2, B3
that can be used to replace, for example [PetOwner], [PetsName] and
[DayOfTheWeek] with a variables?
TIA