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?
Try .Bold := TRUE instead. This has always worked for my own automation routines…
That does not work . An error message appears wich says that the value should be an Integer instead of an Boolean.
In this case, try .Bold := -1 I just checked my reports - I used TRUE for Excel and -1 for Word, but I did a lot more Excel than Word [;)]
Heinz, That doesn’t work either. I think your code is OK but the reason it doesn’t work in my case is the way of the selection of the text or maybe the use of bookmarks.[?] Maybe you can send me a part of code you used in one of your reports, especially code where you also use bookmarks. Thanks for your help so far! Kind regards, Marcel
Marcel, I have used bookmarks, but I haven’t set any of them to bold etc. Anyways - the Font property always has a Bold property, so setting this property to -1 or TRUE is supposed to work, regardless of what object the Font belongs to and how it is selected. There’s yet another thing that comes to my mind when I look at your code - the Automation mechanism seems to have problems when too many objects are resolved in a single expression, i.e. a.b.c.d… It seems that at some point, the precise object type can not be determined any more. I would ask you to try another thing - break up the expression WordBookmark.Range.Font.Bold in e.g. wdRange := WordBookmark.Range; wdFont := wdRange.Font; wdFont.Bold := -1; Tell me if this doesn’t work either, then I’ll try to implement and check if your code works on my system.
Working with bookmarks, i remember that i had problem like Marcel. If you use range with bookmarks you get only a adress like a cursor-posititon (start and end are the same). So setting the range to bold has no effect. Check the content of your range (for example: message(’<<%1>>’,Range.text) If get no content and you can’t expand the range (on a word or a paragraph) you have to work with 2 Bookmarks Bye (Stefan);
Thanks Heinz and Stephan, The following code was the solution to the problem: 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! It was not necesarry to work with two bookmarks. Thanks!!! Marcel