Solved

word.basic and delphi 3

Posted on 1998-05-25
3
282 Views
Last Modified: 2011-09-20

Hi,
I'm trying to write some texts at bookmarks in a word document.
I'm using delphi 3.02 and office pro 97 sr1.
I have a doc called test.doc the file has some text in it and has a bookmark
called 'test'.
--------------------------
I have the following proc :

PROCEDURE TForm3.Button1Click(Sender: TObject);
VAR
     WordDoc : oleVariant;
BEGIN
     TRY
          WordDoc := GetActiveOLEObject('Word.Application');
     EXCEPT
          WordDoc := CreateOLEObject('Word.Application');
     END;

     WordDoc.Documents.Open('c:\temp\test.doc');
     if WordDoc.ActiveDocument.Bookmarks.Exists('test') then
     begin
     (* it is working until here, the file opens correctly and it says that
        the bookmark is existing, but with the following line at runtime
        I have a error that says something like "bookmarks is not a valid method"
        I supose my calling method must be wrong, the syntax looks like what I
        saw in word basic, except that it doesn't work. *)
       
          WordDoc.ActiveDocument.bookmarks('test').select;
     end;


//     WordDoc.Insert('This is the first line'#13);
//     WordDoc.Insert('This is the second line'#13);
//     WordDoc.FileSaveAs('c:\temp\test.doc', 3);
END;
--------------------------
What's wrong guys ?
What I try to do, is go to bookmark and insert some text. Maybe there is another
technic. Anyway I'd like to know what is wrong here.
Any hint someone ?
Jeurk.
0
Comment
Question by:jeurk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
d003303 earned 70 total points
ID: 1347661
Yo,
here's some code that does the job. I used the VBA-Editor and its class browser to get the approptiate methods and properties.

procedure TForm1.Button1Click(Sender: TObject);
var
  Word,
  WordDoc : OLEVariant;
  Index   : LongInt;
begin
  try
    Word := GetActiveOLEObject('Word.Application');
  except
    Word := CreateOLEObject('Word.Application');
  end;
  WordDoc := Word.Documents.Open('c:\temp\test.doc');
  if WordDoc.Bookmarks.Exists('test') then
   begin
     Index := 1;
     while Index <= WordDoc.Bookmarks.Count
      do if WordDoc.Bookmarks.Item(Index).Name = 'test'
          then Break;
     WordDoc.Bookmarks.Item(Index).Select;
     Word.Selection.InsertAfter('This is the first line'#13);
     Word.Selection.InsertAfter('This is the second line'#13);
     WordDoc.SaveAs('c:\temp\test2.doc', 3);
   end;
end;

Have fun,
Slash/d003303
0
 
LVL 4

Author Comment

by:jeurk
ID: 1347662
Hi,
You only get C, cause there was some work on your code.
by the way the answer to my question was :
 WordDoc.Bookmarks.Item('test').Select;

Anyway thanks for the help.
Jeurk
0
 
LVL 4

Expert Comment

by:d003303
ID: 1347663
Sure, no prob.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question