?
Solved

OLE with Word

Posted on 1997-08-29
7
Medium Priority
?
321 Views
Last Modified: 2010-04-06

In one of my softwares, I use OLE to transfer data into a Word file.  Each time I use this code, I open a NEW Word window.  How can I insert the data in the ACTIVE DOCUMENT if Word is already open?
0
Comment
Question by:jpdupont
[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
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:sassas081597
ID: 1342899
I did not test the code bellow. That is why I write a comment. If I am correct - you can ask me to write the answer.

procedure TForm1.Button1.Click(S: TObject);
begin
    V:=CreateOleObject('Word.Basic');
    If v.documents.count>0 then
       v.documents[1].activate
    else
       v.FileNew('Normal');
    v.Insert('I want to insert something there');
end;
0
 

Author Comment

by:jpdupont
ID: 1342900
Your code give the error :
"'documents' method non supported by automation object"
(in french : "Méthode 'documents' non supportée par l'objet automation'"

I use DELPHI 3 in french
WORD97 french

My code :
=========
procedure TPHOTOTHEQUE.SpeedButton7Click(Sender: TObject);
var v:variant;
begin
   V := CreateOleObject('Word.Basic');
   V.AppShow;
   V.FileNew;
   if DataModule1.Table1NOMIMAGE.Value <>'' then
   begin     v.InsertPicture(REP_I_DATA+'\'+DataModule1.Table1NOMIMAGE.Value,true,false);
      V.Insert(#13+#13+DataModule1.Table1LEGENDE.Value);
   end;
==========
works fine but always open a NEW Word window. How can I insert the data in the ACTIVE DOCUMENT if Word is
                     already open?

0
 
LVL 1

Accepted Solution

by:
sassas081597 earned 100 total points
ID: 1342901
Here is what you need!

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  StdCtrls, OleAuto, ComObj, ActiveX;

procedure TPHOTOTHEQUE.SpeedButton7Click(Sender: TObject);
var v:variant;
  ClassID: TCLSID;
  Unknown: IUnknown;
  x: IDispatch;
begin
  try
    ClassID := ProgIDToClassID('Word.Basic');
    OleCheck(GetActiveObject(ClassID, nil, Unknown));
    OleCheck(Unknown.QueryInterface(IDispatch, x));
    V:=x;
    V.AppShow;
    V.Insert('Hallo from Delphi');{or what you really need}
  finally
     v:=Null;
  end;
end;

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jpdupont
ID: 1342902
Its OK when WORD is loaded.
Error if Word isn't loaded !!!

0
 

Author Comment

by:jpdupont
ID: 1342903
Its OK when WORD is loaded.
Error if Word isn't loaded !!!

0
 
LVL 1

Expert Comment

by:sassas081597
ID: 1342904
AS you see, I added TRY statement.
try
......
v.Insert('Hallo');
except
v:=CreateOleObject('Word.Basic');
.......
end;
v:=Null;
0
 

Author Comment

by:jpdupont
ID: 1342905
It's FINE !
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

771 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