Solved

word.basic and delphi 3

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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 …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now