Hi, hope this helps you. I am using D2010 and Office 2010
What I do: if I find the bookmark name, I insert the word Document at this point
Part of my code:
try Template := EmptyParam; NewTemplate := true; ItemIndex := 1; try Wdapplication.Connect; except Screen.Cursor := crDefault; MessageDlg('No se detecta Word Puede no estar instalado(1) o versi?n incorrecta de Word', mtError, [mbOK], 0); Abort; result := False; end; Wdapplication.Visible := true; // False; WdApplication.Caption := 'Kalemat automation'; {Turn Spell checking of because it takes a long time if enabled and slows down Winword} WdApplication.Options.CheckSpellingAsYouType := false; WdApplication.Options.CheckGrammarAsYouType := false; lbInfo.Lines.Add('Word connected'); except on E: Exception do begin ShowMessage(E.Message); WdApplication.Disconnect; result := False; Exit; end; end; //- if wdapplication.Documents.Count > 0 then begin Screen.Cursor := crDefault; MessageDlg( 'Por Favor cierre todos sus Word-documentos antes de proseguir...', mtWarning, [mbRetry], 0); wdApplication.Visible := true; WdApplication.Disconnect; result := False; exit; end else begin with WdApplication do begin // OnQuit := WordAppQuit; // OnChangeDocument := WordDocChange; // OnOpenDocument := WordDocOpen; // OnPreCloseDocument := WordPreClose; // OnCloseDocument := WordDocClose; // DisableSystemCloseBox; end end; {Create new document} Template := EmptyParam; NewTemplate := false; oNewDocument := ModEsc; // abre documento lbInfo.Lines.Add('Abriendo escritura '+ModEsc); WdApplication.Documents.AddOld(oNewDocument, NewTemplate); // Conecta con al instancia de Word WdDocument.ConnectTo(WdApplication.Documents.Item(ItemIndex)); sBookMarkName := 'FPROEMIO'; lbInfo.Lines.Add('Busca marcador Proemio'); if WdDocument.Bookmarks.Exists(sBookMarkName) then begin // ShowMessage(' -Existe: '+sBookMarkName); owhat := wdGotoBookMark; owhich := unAssigned; ocount := unAssigned; //-->>> // ShowMessage(' -Ve a..: '+sBookMarkName); //-->>> // Ve a ese marcados addendum wdDocument.GoTo_(oWhat, oWhich, OCount, sBookMarkName); // ShowMessage(' GoTo_.. ya estoy en: '+sBookMarkName); // Lo encontre oRange := ''; oConformConv := false; oLink := false; oattachment := false; fl_Name := proemi; lbInfo.Lines.Add('Insertando Proemio '+Proemi); if not FileExists(fl_name) then begin Screen.Cursor := crDefault; lbInfo.Lines.Add('No Existe Documento PROEMIO '); MessageDlg('Documento FPROEMIO NO EXISTE, Revise el modelo de escritura', mtError, [mbRetry], 0); end else wdDocument.Bookmarks.Item(sBookMarkName).Range.InsertFile(Fl_Name, oRange, oConformConv, oLink, oattachment); // ShowMessage(' -.. inserte el addendum'); end else begin lbInfo.Lines.Add('No Existe Marcador PROEMIO '); end;
source share