Can anyone help me with the following problem?
I've created a report that uses automation to export data to MS Word. I want the text placed at the boomark to be bold. For this i wrote the following code:
NameBookmark := 'BookmarkA';
WordBookmark := wdDoc.Bookmarks.Item(NameBookmark);
WordBookmark.Select();
WordBookmark.Range.Font.Bold := 1;
WordBookmark.Range.Text := 'Text';
Using this code the text will not be shown Bold.
What am i doing wrong?
Best Regards,
Marcel Bierens
0
Comments
Variables:
wdApp Automation Microsoft Word 9.0 Object Library: Application
wdDoc ..Document
wdRange ..Range
wdBookMarks ..Bookmarks
wdBookMark ..Bookmark
TemplateName Text 250
NameBookmark Text 30
TemplateName := 'C:\myTemplate.dot';
NameBookmark := 'myMark';
IF NOT CREATE(wdApp,FALSE) THEN ERROR('WORD couldn't start');
IF NOT EXISTS(TemplateName) THEN ERROR('File %1 not found',TemplateName);
wdApp.Visible(TRUE); //or Visible:= TRUE;
wdApp.ScreenUpdating(TRUE); //or ScreenUpdating:= TRUE;
wdApp.Activate;
wdDoc := wdApp.Documents.Add(TemplateName);
wdBookMarks := wdDoc.Bookmarks;
IF NOT wdBookMarks.Exists(NameBookmark) THEN
ERROR('Bookmark not found');
wdBookMark := wdBookMarks.Item(NameBookmark);
wdRange := wdBookMark.Range;
wdRange.Text('Text'); //or Text := 'Text';
wdRange.Bold(1); //or Bold := 1;
I solved the problem using the following code:
NameBookmark := 'NameOfBookmark';
WordBookmark := wdDoc.Bookmarks.Item(NameBookmark);
WordBookmark.Select();
WordBookmark.Range.Text := 'Text';
wdRange := WordBookmark.Range;
wdRange.Expand();
wdFont := wdRange.Font;
wdFont.Bold := -1;
Using this code the text placed at the bookmark was shown bold!
The problem was the selection of the text, you have to expand the selection before you can edit the font properties. when you don't expand the selection, the selection includes only the bookmark.
Thanks for your help,
Marcel
Marcel Bierens
RIS Plus, LLC