Looking for a suggestion on how to handle a header

  • Thread starter Thread starter John... Visio MVP
  • Start date Start date
J

John... Visio MVP

Does anyone have a suggestion for including two pieces of information in a
header AFTER massaging? I can get the information in the header using
StyleRef, but I would like to truncate the combined string if it is longer
than a certain length and add "..." to the end.


I have an update macro that builds tables, so I can easily add extra code to
the routine to do the combining and massaging of the information, I just
need an idea of where the massaged information can be placed so it can be
picked up by the header.

John... Visio MVP
 
Hi John,

You could put the massaged info into a custom Document Property, and use a DOCPROPERTY field in the header to link to it.
 
Does anyone have a suggestion for including two pieces of information in a
header AFTER massaging? I can get the information in the header using
StyleRef, but I would like to truncate the combined string if it is longer
than a certain length and add "..." to the end.

I have an update macro that builds tables, so I can easily add extra codeto
the routine to do the combining and massaging of the information, I just
need an idea of where the massaged information can be placed so it can be
picked up by the header.

John... Visio MVP

John,

Perhaps you could use a DocVariable in the header.

{DocVariable HeaderText}

In this example code, the text in the document is bound by a bookmark
"HeaderText"

Sub ScratchMacro()
Dim pStr As String
Dim oSect As Section
Dim i As Long
pStr = ActiveDocument.Bookmarks("HeaderText").Range.Text
If Len(pStr) > 25 Then
ActiveDocument.Variables("HeaderText").Value = Left(pStr, 25) &
" ..."
Else
ActiveDocument.Variables("HeaderText").Value = pStr
End If
For Each oSect In ActiveDocument.Sections
For i = 1 To 3
oSect.Headers(i).Range.Fields.Update
Next i
Next oSect
End Sub
 
I had thought of that, but this will happen several times in the document.
So even if I create a Document Property for each pair, I still need to find
someway of referencing each one in the header.

John... Visio MVP

macropod said:
Hi John,

You could put the massaged info into a custom Document Property, and use a
DOCPROPERTY field in the header to link to it.

--
Cheers
macropod
[Microsoft MVP - Word]


John... Visio MVP said:
Does anyone have a suggestion for including two pieces of information in
a header AFTER massaging? I can get the information in the header using
StyleRef, but I would like to truncate the combined string if it is
longer than a certain length and add "..." to the end.


I have an update macro that builds tables, so I can easily add extra code
to the routine to do the combining and massaging of the information, I
just need an idea of where the massaged information can be placed so it
can be picked up by the header.

John... Visio MVP
 
Does anyone have a suggestion for including two pieces of information in a
header AFTER massaging? I can get the information in the header using
StyleRef, but I would like to truncate the combined string if it is longer
than a certain length and add "..." to the end.

I have an update macro that builds tables, so I can easily add extra code
to
the routine to do the combining and massaging of the information, I just
need an idea of where the massaged information can be placed so it can be
picked up by the header.

John... Visio MVP

John,

Perhaps you could use a DocVariable in the header.

{DocVariable HeaderText}

In this example code, the text in the document is bound by a bookmark
"HeaderText"

Sub ScratchMacro()
Dim pStr As String
Dim oSect As Section
Dim i As Long
pStr = ActiveDocument.Bookmarks("HeaderText").Range.Text
If Len(pStr) > 25 Then
ActiveDocument.Variables("HeaderText").Value = Left(pStr, 25) &
" ..."
Else
ActiveDocument.Variables("HeaderText").Value = pStr
End If
For Each oSect In ActiveDocument.Sections
For i = 1 To 3
oSect.Headers(i).Range.Fields.Update
Next i
Next oSect
End Sub

Am I missing something? You take the text at the bookmark HeaderText,
massage it and store it in a Variable called HeaderText. Then you loop
through the first three sections updating the headers. Why update the
headers?

I have a version that works for a single group and the group information
appears in the header. I need it to work for several groups with a different
header for each group. A simple StyleRef will work, but if I need to massage
the information, I need a location to store the information. One possibility
would be to use a style with hidden text.

John... Visio MVP
 
John,
Am I missing something? You take the text at the bookmark HeaderText,
massage it and store it in a Variable called HeaderText. Then you loop
through the first three sections updating the headers. Why update the
headers?

You put a "field" {DocVarialbe HeaderText} in the header. You have your
text somewhere (I used a bookmark as an example). You "massage" or truncate
the text and store it in a document varialbe. You are not looping through
the first three sections. You are looping through the 3 header types in
every section in order to update the field.
 
Hi John,

You can have multiple custom document properties, if need be. It's then a simple matter of referring to the correct one with the
field.

--
Cheers
macropod
[Microsoft MVP - Word]


John... Visio MVP said:
I had thought of that, but this will happen several times in the document. So even if I create a Document Property for each pair, I
still need to find someway of referencing each one in the header.

John... Visio MVP

macropod said:
Hi John,

You could put the massaged info into a custom Document Property, and use a DOCPROPERTY field in the header to link to it.

--
Cheers
macropod
[Microsoft MVP - Word]


John... Visio MVP said:
Does anyone have a suggestion for including two pieces of information in a header AFTER massaging? I can get the information in
the header using StyleRef, but I would like to truncate the combined string if it is longer than a certain length and add "..."
to the end.


I have an update macro that builds tables, so I can easily add extra code to the routine to do the combining and massaging of
the information, I just need an idea of where the massaged information can be placed so it can be picked up by the header.

John... Visio MVP
 
Greg Maxey said:
John,


You put a "field" {DocVarialbe HeaderText} in the header. You have your
text somewhere (I used a bookmark as an example). You "massage" or
truncate the text and store it in a document varialbe. You are not
looping through the first three sections. You are looping through the 3
header types in every section in order to update the field.

Thanks Greg.

That makes sense. The use of "1 to 3" threw me. wdHeaderFooterFirstPage,
wdHeaderFooterPrimary or wdHeaderFooterEvenPages is what I have seen in the
past, but the use of "1 to 3" is more efficient.

The other part that had me confused is that there will only be ONE
DcVariable in the document, so only one variation of the header.

What I am looking for is something like a Docment with a headers that says
"Test VW - Performance",
"Test VW - Economy",
"Test BMW - Some long winded test that gets truncated..."

I am trying to avoid using the word Section because I would prefer not to do
it with Section breaks, but each grouping starts on a new page and has a
line with a special style for "Vehicle" that would contain VW or BMW or...
and another line that would contain a special style for the test type.

I am going to play with StyleRef to see if I can do it with just StyleRef.

John... Visio MVP
 
Thanks macropod,

I still seem to be missing something. How can you have a single header that
adjusts to different document properties? With StyleRef, the content
displayed changes with each new use of a specific style.

John... Visio MVP
macropod said:
Hi John,

You can have multiple custom document properties, if need be. It's then a
simple matter of referring to the correct one with the field.

--
Cheers
macropod
[Microsoft MVP - Word]


John... Visio MVP said:
I had thought of that, but this will happen several times in the document.
So even if I create a Document Property for each pair, I still need to
find someway of referencing each one in the header.

John... Visio MVP

macropod said:
Hi John,

You could put the massaged info into a custom Document Property, and use
a DOCPROPERTY field in the header to link to it.

--
Cheers
macropod
[Microsoft MVP - Word]


Does anyone have a suggestion for including two pieces of information
in a header AFTER massaging? I can get the information in the header
using StyleRef, but I would like to truncate the combined string if it
is longer than a certain length and add "..." to the end.


I have an update macro that builds tables, so I can easily add extra
code to the routine to do the combining and massaging of the
information, I just need an idea of where the massaged information can
be placed so it can be picked up by the header.

John... Visio MVP
 
Hi John,

For that, you'd probably need a combination of Section breaks and/or different first page/add-even page layouts. A solution bsed on
IF fields might also be possible.

--
Cheers
macropod
[Microsoft MVP - Word]


John... Visio MVP said:
Thanks macropod,

I still seem to be missing something. How can you have a single header that adjusts to different document properties? With
StyleRef, the content displayed changes with each new use of a specific style.

John... Visio MVP
macropod said:
Hi John,

You can have multiple custom document properties, if need be. It's then a simple matter of referring to the correct one with the
field.

--
Cheers
macropod
[Microsoft MVP - Word]


John... Visio MVP said:
I had thought of that, but this will happen several times in the document. So even if I create a Document Property for each pair,
I still need to find someway of referencing each one in the header.

John... Visio MVP

Hi John,

You could put the massaged info into a custom Document Property, and use a DOCPROPERTY field in the header to link to it.

--
Cheers
macropod
[Microsoft MVP - Word]


Does anyone have a suggestion for including two pieces of information in a header AFTER massaging? I can get the information
in the header using StyleRef, but I would like to truncate the combined string if it is longer than a certain length and add
"..." to the end.


I have an update macro that builds tables, so I can easily add extra code to the routine to do the combining and massaging of
the information, I just need an idea of where the massaged information can be placed so it can be picked up by the header.

John... Visio MVP
 
Back
Top