PDA

View Full Version : Printing and templates



gav12345
07-24-2012, 05:02 AM
Hello,

We have a bit of an issue regarding templates in Word 2003/2007. We have a custom Word template which we use to insert a document ID number into a document footer. A condition to this is that if the code finds a file path, it will overwrite this with the document ID number, instead of inserting the document number from scratch.

The problem we have is that although our code works fine, and the document ID is inserted / any file path overwritten when opening the document, when we print the document the file path then overwrites the document ID number again. The file path in the footer is the 'Filename' field, and is part of the template on which the problem document is based.

This is a little confusing because when we look at the attached/referenced templates for the document, we can only see our custom template. In addition, we have also changed the template on which the problem document is based, to remove the file path.

Can anyone tell me exactly what is happening when we print the document? Why is our document ID being overwritten by the file path when there seems to be no reference to the original template in our document, and when the template on which the document was based has been changed anyway?

Thanks in advance, Gavin

macropod
07-24-2012, 06:07 PM
Hi Gavin,

Without seeing the code you're now using (I am aware of snippets in other threads), no one is going to be able to say how to resolve the issue.

gav12345
07-25-2012, 02:34 AM
Thanks Paul. The lack of code was because everything looked fine and saved fine in the document - it was only when we printed (we have written no code relating to printing) that we had problems. I was hoping for a 'well, when you print, such and such a template will always overwrite...'...etc.

In fact I think I'm OK with this now. I have changed our code to delete any Filename fields before we insert the document ID, and the document is now printing as we'd like. The code to delete the filename files is:

'Delete fieldnames (file path)
Dim fld As Field
For Each fld In doc.Sections(1).Footers(wdHeaderFooterFirstPage).Range.Fields
fld.Select
If fld.Type = wdFieldFileName Then
fld.Delete
End If
Next
Set fld = Nothing

Thanks, Gavin