Solved

word.basic and delphi 3

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Save pdf file to other location 3 72
System restore point 4 77
Best Firemonkey component pack 1 73
Using idhttp to login to instagram 2 65
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

18 Experts available now in Live!

Get 1:1 Help Now