PDA

View Full Version : Solved: File insert creates an unwanted field



m00f
07-28-2005, 07:19 PM
Hi,

I have written a script to automate the creation of several documents. These documents were already written and I have resaved them into a template file with the appropriate bookmarks for code insertion etc. This all works like a charm.

The problem is that when I insert the template into a new document, a field is generated in the footer of the first page. However this field does not exist in the template (as far as i can tell), and it always resolves into an ugly error:
"Error! Unknown document property name."
across the bottom of all of the documents. When I click reveal code it shows the following:
{ if { docproperty mDocID } = "" "{FILENAME \p}" "{docproperty mDocID \* charFORMAT}" }

The following snippet of code shows the insert occuring:

' Create a new document
Documents.Add DocumentType:=wdNewBlankDocument

ChangeFileOpenDirectory "C:\autoDOC\templates\"

' Insert the template file into the new document
Selection.InsertFile FileName:=docType & ".dot"

How can I prevent this field from being inserted into the document?? is there some magical setting that i have missed in the template file - because this only occurs with some of the template files.

Thanks,
Ryan

MOS MASTER
07-29-2005, 04:32 AM
Hi and Welcome to VBAX! :hi:

There's nothing wrong with that code and I'm sure that the code is not causing the problem.

The insertfile method also takes in the headerfooter from the document to be inserted.

So can you please open that document manualy and go to header footer. Press ALT+F9 to see if those fields are in there as well.

If not could you please attach that document (Which you want to insert) here stripped of private stuff so we can examine it.

This must be in the template or document to be inserted cause otherwise it wouldn't make sence.

HTH, :whistle:

m00f
07-31-2005, 07:59 PM
Thx for the welcome,

I managed to solve the problem - it was a custom document property that was added in by the lawyers system when they reviewed the document. I was able to remove it fairly easily. Thanks for the prompt response anyway.

Cheers,
Ryan
:beerchug:

MOS MASTER
08-01-2005, 09:47 AM
Hi Ryan, :yes

You're most welcome! :beerchug: