Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word w/ Delphi: String Too Long 2

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I'm using a technique that I've used in the past to merge information from Delphi to Word:

Code:
procedure MergeData(varWord: variant; strBookMark: string; strData: string);
  begin
  // if the Bookmark is defined in the document then add the string at that
  // location.
    if varWord.ActiveDocument.Bookmarks.Exists(strBookMark) = True then
      varWord.ActiveDocument.FormFields.Item(strBookMark).Result:= strData
  end;

works great, however, I have run into an issue. I have a very long string that I'm trying to pass into a bookmark that has 'Unlimited' as the length. I have tried changing it to a large number 2000 which is plenty long enough for the text, but that didn't work either. However I can type ALL the information into the bookmark. I just can't pass it programatically.

Any suggestions on how I can get my long string into the bookmark?

Thanks!



Leslie

Essential for database developers:
The Fundamentals of Relational Database Design
Understanding SQL Joins
 
I did understand and read what you said. I removed the FormField and replaced it with a bookmark (Insert -> bookmark). I CAN NOT transfer directly to the bookmark. I looked at the methods available for the bookmark (the here link above: and can not see how to programatically transfer information from my Delphi application to a "real" bookmark in a word document. I CAN transfer information into a form field.

When I use this code:
Code:
ActiveDocument.Bookmarks("bmNotes").Range.Text _
    = strData

I get an error message that 'Bookmarks is not a valid method'. The only methods that I can find for a bookmark (from the link above) are:
Add
Exists (which I use and works!)
GetEnumerator

There are some public properties of the bookmark:
Application
Count
Creator
Default Sorting
Item
Parent
ShowHidden

but no where can I find how to transfer a long string into just a bookmark. I can transfer a short string into a form field. I can not transfer a long string into a form field. I have a long string that I need to transfer.

I would like to take this code which will solve my problem:
Code:
// if the Bookmark is defined in the document then
// add the string at that location.
  If varWord.ActiveDocument.Bookmarks.Exists(strBookMark) _
          = True Then
      With varWord.Selection
         .GoTo what:=wdGoToBookmark, Name:= strBookmark
         .Collapse
         .MoveRight wdCharacter, 1
         .TypeText Text:=strData
      End With
  End If

and convert it to "Delphi Speak" so that I can overcome this issue.

I appreciate your explanations of bookmarks and I really do understand what you are saying, but I'm limited by what is publicly available

Leslie
 
What about this ?
if varWord.ActiveDocument.Bookmarks.Exists(strBookMark) = True then
varWord.ActiveDocument.Bookmarks.Item(strBookMark).Range.Text:= strData;

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
On Sept. 27 I posted:
Code:
// if the Bookmark is defined in the document then 
// add the string at that location.
  If varWord.ActiveDocument.Bookmarks.Exists(strBookMark) _
          = True Then
     varWord.ActiveDocument.Bookmarks(strBookmark) _
              .Range.Text = strData

OK, PH, if I am reading the OP correctly,

varWord.ActiveDocument.Bookmarks(strBookmark) _
.Range.Text = strData ' does not work

varWord.ActiveDocument.Bookmarks.Item(strBookMark)
.Range.Text:= strData ' does work

why would it require a .Item?

faq219-2884

Gerry
My paintings and sculpture
 
Thanks again for everyone's help on this. It will be a huge help in the future to not have to limit the size of the strings that I transfer into Word.

I did have one additional question...Once I have inserted a bookmark, is there anyway to see it? Or at least see the location where it's been placed?

Thanks!

Leslie
 
I don't know the spelling as I don't use an english version of office:
menu Display -> Show marks

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OOps, sorry :~/
menu Tools -> Options ... -> tab Display -> tick Bookmarks

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top