copying data between headers

H

happysad

Hi,

I am creating some templates in Word 2007 that have space in the header for
the user to enter - stuff like "Project", "Group", "Meeting date" and so on.
The header on the first page contains more information than the following
headers. So there are two different headers, requiring the user to enter some
of the data twice. I need a way to copy the shared data from the first to the
following headers, so he only needs to enter it once.

Stuff I've tried:

1. STYLEREF field: doesn't work from headers, only from the main document.

2. Content control linked to the 15 Document properties (Quickparts): Works
great in the template, but doesn't work in the document created from the
template.

3. OLE Link: Works in the template, but not in the document created from the
template - referenced (template) file cannot be found.

4. Content controls and a VBA macro using the event
Document_ContentControlOnExit
to copy data between controls with the same title. Works great in the
template, but the macro doesn't run in the document created from the
template. If I add the macro to Normal.dotm, it also doesn't work. But, if I
create the document from the template, then save it as a macro-enabled
document (.docm), close it, re-open, then it works. The template macro runs.
But this is not really satisfactory...

Can you help me?
 
D

DaveLett

Hi,
I think you have a couple of options, at least.

1) If the user enters the "data" in the Word document at a certain location,
then you can bookmark that data and reuse it with a { Ref "NameofBookmark" }
field. However, regular users routinely delete these bookmarks accidentally.

2) If you have a macro that runs as the user opens the document or creates a
new one, then you can store the data in a Custom document property., which
you can then display in the document by using a { DocProperty
"NameofCustomProperty" } field.

BTW, I tried using a StyleRef field in the header and it's working just as
expected.

HTH,
Dave
 
H

happysad

Thank you,
Hi,
I think you have a couple of options, at least.

1) If the user enters the "data" in the Word document at a certain location,
then you can bookmark that data and reuse it with a { Ref "NameofBookmark" }
field. However, regular users routinely delete these bookmarks accidentally.

I tried the bookmarks previously, but didn't get it to work. Also, the
bookmarks are invisible, which makes them hard to work with. I may have to
try them again though.
2) If you have a macro that runs as the user opens the document or creates a
new one, then you can store the data in a Custom document property., which
you can then display in the document by using a { DocProperty
"NameofCustomProperty" } field.

The custom document property is, as I understand it, an extension of the 15
default document properties. I already tried this approach with the default
15, and I could only get it to work in the template, not in the document.

Question regarding macros:

Is it designed behaviour that the macro I create in the template
(Document_ContentControlOnExit) doesn't run when I create the document? If
not, what could prevent it being run? I have "Run all macros" enabled in my
security settings.
BTW, I tried using a StyleRef field in the header and it's working just as
expected.

Are you sure it works when both the text marked with the style as well as
the referenced field are in different headers? This didn't work for me, but I
may have to try it again.
 
H

happysad

Yay, I got it working with a bookmark and a REF field. This works in both the
template and, crucially, the document as well.

It's too bad that the bookmark is invisible though. It's easy to enter data
outside it, or delete it as you say. I will look for a way to enable "Show
bookmarks" when the document opens.
 
H

happysad

I think I have found the ideal solution now.

I use a content control with a bookmark INSIDE it. Then, I check "Cannot be
deleted" on the content control. Now, the magic happens - the bookmark
becomes impossible to delete, and impossible to write outside! And the
content control is easier to see in the document as well.
 
L

Lene Fredborg

You can make bookmarks visible:
Word 2003: Tools > Options > View tab > Bookmarks (found in the Show group).

Word 2007: Office button > Word Options > Advanced category. You will find
“Show Bookmarks†in the “Show document content†group.

When that option is turned on, bookmarks appear as gray, square brackets
around the bookmarked content. If no content is included, it looks like a
gray insertion point.

To show the bookmarks via VBA:

ActiveWindow.View.ShowBookmarks = True

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
H

happysad

I have a major problem. It seems that the bookmarks dissappear/are suppressed
when the document is opened on any other PC. This goes for both the dotx and
the docx files.

The fields that refer to them show the "ERROR..." text.

It seems I have misunderstood the concept of bookmarks. I have searched on
the web for an explanation but hasn't found any.
Are they bound to the user or what is the explanation - is it working as
designed? How can I get around this problem?

Thank you very much in advance.
 
H

happysad

Are you sure it works when both the text marked with the style as well as
the referenced field are in different headers? This didn't work for me, but I
may have to try it again.

Just tested this again. Here are the results:

1. Text in main document -> StyleRef field in main doc: OK
2. Text in main document -> StyleRef field in header: OK
3. Text in 1st header - > StyleRef field in main doc: Doesn't work.
4. Text in 1st header - > StyleRef field in 2nd header: Doesn't work.

Unfortunately, it is case #4 I need.

What I dislike about Word is how arbitrary/illogical it often seems...
 
G

Graham Mayor

That's how Styleref fields are supposed to work (or not as the case may be).

Your original message indicated that users enter date in the header, which
is highly impractical. If you need to collect data to insert in various
parts of the document, the most elegant method is by means of a userform.
You can then store and/or insert the results of the gathered data wherever
you want. For the basics, see Word MVP FAQ - Userforms
http://word.mvps.org/FAQs/Userforms.htm

For a more in depth explanation, see
http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm

You may find http://gregmaxey.mvps.org/Repeating_Data.htm useful also.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

happysad

Thank you for the advice. I am upgrading some old Word 2000 templates (by
recreating them from scratch), and they had the data-entry into header
functionality (by using document properties it seems).

The client said he didn't want any user forms. But maybe we'll have to
reconsider.
 
G

Graham Mayor

It's either that or ASK fields. :(
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

That Guy

You could insert a text box with some text fields in it that take the
data.

Then make a button in the same text box with a macro behind it that
enters the data and then hides the text box using ActiveDocument.Shapes
(X).visible = msoFalse

of course substituting the shape index for X. If this si the only text/
picture box etc in the document the index should be 1.

I don't have word 2007 but this works in 2003.

I can provide an example upon request.
 

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