whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

36 Visitors Online


 
...insert text at a Bookmark (MS Word)?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (30):  
     


uses
  
ComObj;

procedure TForm1.Button1Click(Sender: TObject);
const
  
// Word Document to open
  // Dein Word Dokument
  
YourWordDocument = 'c:\test\worddoc.doc';
var
  
BookmarkName, Doc, R: OleVariant;
begin
  
// Start a Word instance
  // Word Instanz Starten
  
try
    
WordApp := CreateOleObject('Word.Application');
  except
    
ShowMessage('Could not start MS Word!');
  end;
  // Open your Word document
  // Dok. öffnen
  
WordApp.Documents.Open(YourWordDocument);
  Doc := WordApp.ActiveDocument;

  // name of your bookmark
  // Name der Textmarke
  
BookmarkName := 'MyBookMark';

  // Check if bookmark exists
  // Überprüfen, ob Textmarke vorhanden
  
if Doc.Bookmarks.Exists(BookmarkName) then
  begin
    
R := Doc.Bookmarks.Item(BookmarkName).Range;
    // Add text at our bookmark
    // Text bei Textmarke einfügen
    
R.InsertAfter('Text bei Textmarke');
    // You make a text formatting like changing its color
    // Man kann nun auch den Text formatieren. z.B die Farbe wechseln.
    
R.Font.Color := clRed;
  end;

  // Save your document and quit Word
  // Dokument Speichern und Word beenden.
  
if not VarIsEmpty(WordApp) then
  begin
    
WordApp.DisplayAlerts := 0;
    WordApp.Documents.Item(1).Save;
    WordApp.Quit;
    BookmarkName := Unassigned;
    R := Unassigned;
    WordApp := Unassigned;
  end;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners