Word NewDocument

Add-in Express™ Support Service
That's what is more important than anything else

Word NewDocument
type mismatch error message 
Nicholas Glasier

Posts: 110
Joined: 2005-02-12
I'm trying to create a new blank document based on the template of an existing document, but keep getting an error message "Wrong type"

intf: IDispatch;
IDoc, NewDoc: Word2000._Document;
ATemplate, isTemplate, aDocType, aVisible: OLEVariant;

Intf := WordApp.ActiveDocument;
Intf.QueryInterface(Word2000._Document, IDoc);
if ExtractFileExt(IDoc.Name)= '.dot' then
isTemplate := true
else isTemplate := false;
ATemplate := IDoc.Get_AttachedTemplate;
aDocType := wdNewBlankDocument;
aVisible := true;
NewDoc := WordApp.Documents.Add(aTemplate, isTemplate, aDocType, aVisible);

The parameters are all olevariants as you can see, and debugging shows the code before the last line runs ok, but WordApp.Documents.Add raises a Type Mismatch error. What am I doing wrong please?

Posted 07 Apr, 2005 00:42:17 Top
Dmitry Kostochko

Add-in Express team

Posts: 2740
Joined: 2004-04-05
Hi Nick,

MSDN quotation:
Template - Optional Variant. The name of the template to be used for the new document. If this argument is omitted, the Normal template is used.

So, try to pass the attached template Name instead of the Template object.

Posted 07 Apr, 2005 05:44:09 Top