I need to be able to open and edit a Word template from Delphi (using Word). I can open the OK template, but Word assumes that this is a document, not a template.
The problem is that I need to edit the template and not use it as a template for a new document. I use templates as part of a workflow system, and I want users to be able to edit templates from my application. As of now, they should open Word, and then open the template from there and edit it - making it from my application will be easier and safer.
Experimental code
fWordApp: WordApplication; TempName: OleVariant; WordDoc: WordDocument; TemplateFile: string; begin TemplateFile := Settings.Directories.RootInsert(qryTemplates.FieldByName('fldtemplate_path').AsString); if TemplateFile <> '' then begin if not Assigned(fWordApp) then begin fWordApp := CreateOleObject('Word.Application') as WordApplication; while fWordApp.Templates.Count = 0 do Sleep(200); // Normal.dot must be loaded end; if Assigned(fWordApp) then fWordApp.Visible := True else raise Exception.Create('Cannot initialize Word application'); TempName := TemplateFile; WordDoc := fWordApp.Documents.Add(TempName, EmptyParam, wdFormatTemplate, EmptyParam);
source share