Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Header in Word

Status
Not open for further replies.
Nov 15, 2000
322
0
0
US
I have a document template that uses find/replace tags. A 3rd party application opens the template and saves a new instance of a document after doing a find/replace on the tags.

For example, the address section of the letter may look like:

Code:
<<CUSTOMERTITLE>> <<CUSTOMERNAME>>
<<CUSTOMERSTREET1>>
<<CUSTOMERSTREET2>>
<<CUSTOMERCITY>>, <<CUSTOMERSTATE>> <<CUSTOMERZIP>>

The app then looks for tags that it has associated with data in its own database and replaces them with the right values.

I need to be able to have the text and a logo in the header section be conditional based on the value in one of these tags. I have a <<COMPANY#>> tag, and based on that, I need a different header.

Any thoughts on how to go about that?

Monkeylizard
Sometimes just a few hours of trial and error debugging can save minutes of reading manuals.
 
What do you mean by a value "[b[]in[/b]" the tag?

In any case, use a Select Case to determine things.

Select Case some value "from" a tag
Case whatever
put in header A
Case a different value
put in header B
Case third value
put in header C
End Select

You do not give enough detals to go much beyond that. For example, if the various header content (text and logo) were already AutoText entries, then it would be VERY easy.
Code:
Select Case [i]some value "from" a tag[/i]
   Case  whatever
         NormalTemplate.AutoTextEntries("Header_A").Insert _
              Where:=ActiveDocument.Sections(1) _
                .Headers(wdHeaderFooterPrimary).Range, _
              RichText:=True
   Case  a different value
         NormalTemplate.AutoTextEntries("Header_B").Insert _
              Where:=ActiveDocument.Sections(1) _
                .Headers(wdHeaderFooterPrimary).Range, _
              RichText:=True
   Case third value
         NormalTemplate.AutoTextEntries("Header_C").Insert _
              Where:=ActiveDocument.Sections(1) _
                .Headers(wdHeaderFooterPrimary).Range, _
              RichText:=True
End Select
You get the testing value - I am not sure how you intend to do that - test it, and depending on the value, make the header A, B, or C.

Gerry
 
Tag" may not be the right word for this. Basically the 3rd party app has a list of predefined words that I have to encase with the "<<" and the ">>". when it finds one of it's predefined words in that encapsulation, it replaces the whole "tag" with the value of the database field that it associates with that "tag" word. So in my example, If I was generating a letter to a customer, the template would have the "tags" as shown and the app would replace them with the actual name and address of the customer record I'm working with.

What I meant by a value "in" the tag for determining the header, was that one of the predefined tag words from the app is a <<CompanyCode>>. I would want a case around whatever value the app replaced that "Tag" with.

So If I had a template that had <<CompanyCode>> located somewhere on it, the app would replace that with text like "001" or "034". Based on that numeric value, I would then want to set the text and logo of the header.

I'm familiar with case statements, but I've never heard of using one in Word. Where would I put that? Is it done in a macro, or some kind of VBScript?

Monkeylizard
Sometimes just a few hours of trial and error debugging can save minutes of reading manuals.
 
We would need to know what the 3rd party app is doing... this is really an issue with the 3rd party app, not word.

By the way, why wouldn't you just use Mail Merge? You could accomplish the differently formatted header by creating alternate fields for the "special" cases and leaving them blank for others. The problem comes in with the image. Mail Merge doesn't do images (confirmation?).

You will probably want some Visual Basic for that. My first instinct is to have a field with the path and filename of the logo. Hell, if you want, put the pixel dimensions in as well. Then you could have VB search your letters for the file paths ans replace it with the images, with those dimensions. But that's going to be tricky, and it is too late for me to be writing that kinda code.
 
> Mail Merge doesn't do images (confirmation?).
Wrong. Mailmerge can be used to conditionally display an image embedded in the document or linked with the document via an INCLUDEPICTURE field. It's just a matter of coding the field correctly.


Cheers
[MS MVP - Word]
 
Thanks everyone. That gives me something to go on. At least now I know it's probably possible to do what the business owners want, it's just beyond our current internal skill-set. A consultant may be in order.

Monkeylizard
Sometimes just a few hours of trial and error debugging can save minutes of reading manuals.
 
Possibly. I'll look into it on Monday.

Monkeylizard
Sometimes just a few hours of trial and error debugging can save minutes of reading manuals.
 
I was wrong about the <<>> being find/replace. They are indeed "fields" in the word document. It looks like an IF on the fields may do the trick.

Thanks, everyone.

Monkeylizard
Sometimes just a few hours of trial and error debugging can save minutes of reading manuals.
 
Reading manuals is great but you need to know which part of the manual to read or which keyword to search for. eg when they replaced frames on word 2 it took me ages to figure out that they were called text boxes on word 2000. With Word 2007 the whole learning process starts again - takes ages to find the features I want.
 
Hi monkeylizard,

Given that they're fields, the chevrons suggesst they're probably mergefields. You can confirm this by selecting one of the fields (eg «CUSTOMERTITLE») and pressing Shift-F9. If it's a mergefield, the code should convert to:
{MERGEFIELD CUSTOMERTITLE}

Continuing the MERGEFIELD hypothesis, your «COMPANY#» field could could be incorporated into a set of IF tests in the header, coded along the lines of:
Code:
{IF«COMPANY#»= "ABC" "ABC Logo here"}{IF«COMPANY#»= "XYZ" "XYZ Logo here"}

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message. Likewise, you can't type or copy & paste the chevrons (ie '« »') - they're part of the actual mergefields, which you can insert from the mailmerge toolbar.

xyb: Word 2007 really hasn't changed anything substantively in this area, so I can't really see how your post contributes to a solution to the OP's problem ...


Cheers
[MS MVP - Word]
 



IMHO this would be much MUCH easier to do in the source data file, especially if it were Excel.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Skip,

The OP requires:
the text and a logo in the header
I can't see how modifying the data source will facilitate the logo's inserftion. An IF test in the mailmerge main document can handle both the text and logo.


Cheers
[MS MVP - Word]
 
macropod - it doesn't. The suggestion to use field if was already suggested on 18Apr.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top