Using letterhead template via code

R

R. Choate

I have a large Word app that I built a long time ago for a client. Now they are using a new PDF system and the letterhead graphic is
now to be handled in Word instead of in the PDF driver. What I mean there is that the company letterhead, which goes down the side
and across the top, is to be applied in Word and layered over the letter which the app creates. The letterhead is not to be used all
the time, so I have to be able to basically turn that on or off.

The client has given me a template with the letterhead graphic embedded into the header/footer layer. My app is also a template and
is loaded into the Office/Startup area with other templates. I would like to have my app create the letter as it has always done,
but use the template they gave me to attach their letterhead. This would be the least painful thing to do I believe. It would
probably be easier to have the graphic on the header/footer layer of my own app, but I've put the graphic there and when the letter
is created, the letterhead graphic is nowhere to be seen. This is the one big Word app I've ever built. I'm usually an Excel and
Access guy, but this app is substantial and is userform driven. There is tons of code already invested so I really need to make this
letterhead piece work. I've studied the code but I cant figure it out. I'm hoping you can help me.

There is a piece of code where it says document.add Template:="", NewTemplate:=false

I may not have quoted that snippet exactly but I'm sure you know the method. I've tried changing the "" and putting my letterhead
template path and name inside the double quotes, but that does not result in the letterhead showing up either. I'm stumped. Lets
assume for now that both the main app and the letterhead template (which both have .dot extensions) are on the desktop.

Thanks in advance!
 
C

Charles Kenyon

See http://addbalance.com/word/templatesmenu.htm.

strPath = "C:\Documents and Settings\All Users\Documents\Shared Templates\"
strName = "letterhead.dot"
Documents.Add Template:= strPath & strName, _
NewTemplate:=False, _
DocumentType:=wdDocument, _
Visible:=True
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Chuck

probably be easier to have the graphic on the header/footer layer of my own
app,
but I've put the graphic there and when the letter
is created, the letterhead graphic is nowhere to be seen.

Are you sure you put the graphic in the right header/footer? There are
three types of headers/footers: FirstPage (ie different first page), Primary
and OddEven. If you put the graphic in the FirstPage header/footer but don't
have different first page ticked in Page Setup > Layout in the document, then
the graphic might not show.

If you want a graphic to show only on the first page, then put it in the
FirstPage header/footer and make sure different first page is ticked. If you
have a different graphic for continuation pages, put that graphic in the
Primary header/footer. If you have one graphic for all pages it should go in
the Primary header/footer and different first page should not be ticked.

HTH
 
C

Charles Kenyon

Take a look at: How to set up letterhead or some other document where you
want one header on the first page and a different header on other pages.
http://www.addbalance.com/word/headersfooters.htm This gives step-by-step
instructions. (It also has the following links)

Some other pages to look at:

Letterhead Tips and Instructions
http://home.earthlink.net/~wordfaqs/Letterhead.htm

Letterhead Textboxes and Styles tutorial
http://addbalance.com/word/download.htm#LetterheadTextboxesAndStylesTutorial

Template Basics
http://www.addbalance.com/usersguide/templates.htm

How to Create a Template - Part 2 - essential reading
http://www.mvps.org/word/FAQs/Customization/CreateATemplatePart2.htm

Word "Forms"
http://www.addbalance.com/word/wordwebresources.htm#Forms and

Word for Word Perfect Users
http://www.addbalance.com/word/wordperfect.htm if you are coming from a WP
environment (or even if you are not).

If you are interested in creating templates that will work with the letter
wizard or use that wizard, you should look at the chapter on Advanced
Document Formatting in Using Office 2003 (or whatever your version is),
Special Edition, by Ed Bott and Woody Leonhard. It has detailed instructions
including instructions on getting the fields you want from your Outlook
Contacts for addressing a letter. (Chapter 19 of SE Using Office 2003) You
should be able to get this through your public library or at Amazon.com
http://www.amazon.com/exec/obidos/ISBN=0789729555/balancecheckbookA/

Finally, take a look at the letter templates that come with Word. While they
are no great shakes as letterhead, they do use styles and AutoText lists
very well. If you use the same style names that are used in those templates
in your own letterhead for the same parts of the document, you will have
better luck with using the built-in AutoText entries in Word.

Hope this helps,
 
R

R. Choate

I think I better clarify some more. First off, I think I misspoke when I said that my letterhead is residing in/on the header or
footer. I know that in the letterhead template, I cannot select the graphic/letterhead unless I click to view headers and footers,
otherwise it looks like a watermark. So I clicked View>Headers and Footers and then I selected the letterhead graphic (which covers
the whole page) and I copied and then pasted into my own template application in the same header/footer area. I should further
clarify that when I say I pasted into my template, I mean that when I open my template file (xyz.dot) and it shows "document 1",
that is where I open headers/footers and paste the graphic.

In any case, I've tried the code which Charles posted and it does not show the letterhead graphic. The application has always
contained the following code:

'starts new document
documents.add Template:="", NewTemplate:=False

I replaced this with Charles' code (adjusted for the correct info) and got nada.

I do know that if I manually paste the text copied from a letter created by my application onto the blank (blank other than having
the letterhead appearing in the background and looking kind of washed out) that appears when I open the letterhead template
("document 1") , and then go to print preview or just print the document, the letter appears correctly in print preview and it
prints correctly.

I may have mentioned that my application is a .dot file and is very substantial. It creates various letters for a public accounting
firm and is much more "heavy duty" than any canned template. If you were to see it you would likely be shocked that I'm stumped by
this. The thing is about 2 Meg and contains a ton of code. I really need to make this letterhead thing work from code in this file.
I'm very hopeful somebody can show me what I'm not seeing. Perhaps the graphic is not related to the header or footer other than it
appears to be embedded and washed out unless I am in header/footer view. As far as the business about primary, secondary, or other
headers and footers, I don't know how to go to those layers.

As to whether I want the letterhead on just the 1st pg, yes I do. I also only want the letterhead under certain circumstances, but
first I need to get it to work at all (via code). Typically, this template is loaded in the templates for Word and a button is
clicked to open my userform. After that, the user answers a bunch of questions on the form, some of it is automatically filled in
via code, and then they click an "Enter" button on the form and it writes the complete letter.

I hope I have provided enough info for you to help me better.

Thanks !
--
RMC,CPA


I have a large Word app that I built a long time ago for a client. Now they are using a new PDF system and the letterhead graphic is
now to be handled in Word instead of in the PDF driver. What I mean there is that the company letterhead, which goes down the side
and across the top, is to be applied in Word and layered over the letter which the app creates. The letterhead is not to be used all
the time, so I have to be able to basically turn that on or off.

The client has given me a template with the letterhead graphic embedded into the header/footer layer. My app is also a template and
is loaded into the Office/Startup area with other templates. I would like to have my app create the letter as it has always done,
but use the template they gave me to attach their letterhead. This would be the least painful thing to do I believe. It would
probably be easier to have the graphic on the header/footer layer of my own app, but I've put the graphic there and when the letter
is created, the letterhead graphic is nowhere to be seen. This is the one big Word app I've ever built. I'm usually an Excel and
Access guy, but this app is substantial and is userform driven. There is tons of code already invested so I really need to make this
letterhead piece work. I've studied the code but I cant figure it out. I'm hoping you can help me.

There is a piece of code where it says document.add Template:="", NewTemplate:=false

I may not have quoted that snippet exactly but I'm sure you know the method. I've tried changing the "" and putting my letterhead
template path and name inside the double quotes, but that does not result in the letterhead showing up either. I'm stumped. Lets
assume for now that both the main app and the letterhead template (which both have .dot extensions) are on the desktop.

Thanks in advance!
 
C

Chuck

I think I see where at least one problem may be: you're not actually
inserting the graphic into the template:
when I open my template file (xyz.dot) and it shows "document 1",
that is where I open headers/footers and paste the graphic.

Sounds like you're opening a document *based on* the template, not the
template itself. If you open the template itself, the document name in the
title bar would be "xyz.dot". To open the template,

1. choose File>Open
2. in the Open dialog, choose "Document templates (*.dot)" in the Files of
Type combo box
3. choose xyz.dot from the list of files
4. click the open button

Alternatively you can open your file manager, right click on xyz.dot and
choose Open from the popup menu.
 
R

R. Choate

Hi,

I finally got your code to work, except the constant "wdDocument" was not one of the accepted parameters. It only worked if I used
"wdNewBlankDocument" instead. Strange.

Now I have a new problem which started after I got the letterhead working. I posted that in a new thread since it is a different
issue.

Thanks for getting me started! Hopefully you will be able to understand what went haywire with my 2nd page header. Now that I've got
the letterhead going, if the letter goes beyond one page, the entire 1st page text repeats in the header of the 2nd page. I've got
code in my app which I posted in my new post that deals with 2-page letters (or at least it has been dealing with it for five years
before today). This feels like sticking fingers in the dike and having water leak through a new place.

--
RMC,CPA


See http://addbalance.com/word/templatesmenu.htm.

strPath = "C:\Documents and Settings\All Users\Documents\Shared Templates\"
strName = "letterhead.dot"
Documents.Add Template:= strPath & strName, _
NewTemplate:=False, _
DocumentType:=wdDocument, _
Visible:=True
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Charles Kenyon

If you want to change the contents of your template, you need to open it.
You are creating a new document, making changes in that document, and
expecting them to show up in the next new document you create based on the
(unchanged) template. That isn't how it works. For more on the different
kinds of templates, tabs on the file new dialog, and locations of templates
folders see http://addbalance.com/usersguide/templates.htm.
 

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