Solved

word.basic and delphi 3

Posted on 1998-05-25
3
276 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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