[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

word.basic and delphi 3

Posted on 1998-05-25
3
Medium Priority
?
292 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 140 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

656 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