Geoff332
Wed Feb 27 20:32:01 PST 2008
Unfortunately, I can't blank out all of the fields: they are used elsewhere
in the document. In all cases, at least one of them will be populated; I just
want to stop one instance of the field from being displayed. One alternative
is to put the same data in two fields. That'll work, but isn't very elegant.
Users, being users, will change their mind and do strange things. So I need
the solution to work from two possible starting scenarios:
1. The appropriate fields are already in the document (this is how the
document already works).
2. The fields are not already in the document and need to be inserted (this
would happen if someone had previously deleted them).
My idea was to enclose the fields in a bookmark so I know where they are,
then I can remove them (delete the content of the bookmark) or add them
(enclose them in the bookmark) as required. A bookmark seemed like the right
tool to achieve this, but if there's a better approach, then I'll try it out.
I'll look into the links and advice from yourself and fumei and see if I can
figure it out.
Thanks,
Geoff.
"Doug Robbins - Word MVP" wrote:
> Use DocVariable fields in the document (no bookmark required) and use VBA to
> set the value of the corresponding variables and update the fields in the
> document so that the DocVariable field display the values
>
> With ActiveDocument
> .Variables("varprdFamily").Value = "Some Family"
> .Variables("varprdName").Value = "Some Name"
> .Variables("varprdVersion").Value = "Some Version"
> .Range.Fields.Update
> End With
>
> For the above code, you would use the following fields
>
> { DOCVARIABLE varprdFamily }
> { DOCVARIABLE varprdName }
> { DOCVARIABLE varprdVersion }
>
> The beauty about document variables is that you just change the value
> assigned to the variable and update the fields and it works.
>
> However, if you are set on using bookmarks, see the article "Working with
> Bookmarks in VBA" at:
>
>
http://www.word.mvps.org/FAQs/MacrosVBA/WorkWithBookmarks.htm
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Geoff332" <Geoff332@discussions.microsoft.com> wrote in message
> news:71C4C238-24A0-4FE3-BB2E-4DC543A277CC@microsoft.com...
> > The documents in question all relate to a family of products - with custom
> > fields telling me about the product. If document refers to a specific
> > product
> > in the family, then I want to display the product family (prdFamily),
> > product
> > name (prdName) and product version (prdVersion). If a document is either
> > generic or refers to more than one specific product, then I want none of
> > the
> > information displayed.
> >
> > I had originally handled this by leaving the fields there and populating
> > prdName and prdVersion with a space. The problem is prdFamily will always
> > be
> > populated and used elsewhere in the document - but in one instance, I
> > don't
> > want it displayed. To further complicate it, I do want these as dynamic
> > fields and want the document to handle being changed from a specific
> > product
> > to a generic document and back without breaking.
> >
> > The point I had reached was to put the fields inside a bookmark. I can use
> > VBA to delete the fields; I can insert the fields and text at the
> > bookmark,
> > but they are now outside of the bookmark. So if I try and reverse the
> > process
> > again, the inserted fields aren't deleted.
> >
> > Thanks,
> > Geoff.
> >
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> What type of fields are you talking about. It might really be best to
> >> describe the purpose of the document/template rather than, or at least in
> >> addition to the way in which you are trying to accomplish it. There may
> >> be
> >> a better way.
> >>
> >> --
> >> Hope this helps.
> >>
> >> Please reply to the newsgroup unless you wish to avail yourself of my
> >> services on a paid consulting basis.
> >>
> >> Doug Robbins - Word MVP
> >>
> >> "Geoff332" <Geoff332@discussions.microsoft.com> wrote in message
> >> news:29C40D2E-4D54-4A22-A7AA-77E989C31EB2@microsoft.com...
> >> > Hi,
> >> >
> >> > I have a document where I want to enter particular fields and text,
> >> > depending on a condition. When completed, the bookmark should refer to
> >> > the
> >> > inserted text. The fields and bookmarks are already defined in the
> >> > document.
> >> > It's important that the fields be inserted in the bookmark, rather than
> >> > just
> >> > the value.
> >> >
> >> > The code should look something like:
> >> >
> >> > <delete existing bookmark text>
> >> > If (condition) Then
> >> > <add field1 to bookmark>
> >> > <add text to bookmark>
> >> > <add field2 to bookmark>
> >> > Else
> >> > <add field3 to bookmark>
> >> > End If
> >> >
> >> > The cleanest way to do it would be to build the appropriate insert
> >> > string
> >> > then replace the bookmark. I can do this easily with text, but not with
> >> > fields.
> >> >
> >> > Any suggestions would be much appreciated.
> >> >
> >> > Thanks,
> >> > Geoff.
> >>
> >>
> >>
>
>
>