Solved

OLE, Excel

Posted on 1998-07-08
13
485 Views
Last Modified: 2010-04-04
Hello,

 Here I'm again with possible a stupid question, but I've got to know it and then again only stupid answers exist ;-)

Here I know how to do OLE with Excel, but I've always read about creating a variant which contains an instance of a Com object called IDispatch. Now, for the ease let's only talk about Variant (V) contains a 'thing' for talking to Excel.

This 'thing' can be created with CreateOleObject and then you can begin communicating with Excel. Well, when you create such a 'thing' an instance of Excel is created. But what if Excel is already opened? How can I create to this already opened Excel? If this is the case I don't have the 'thing' which refers to the open Excel! And if V doesn't contains such a 'thing' I can't communicate with this Excel.

So this is what I want to know :

 If Excel is running, how do I get a handle ('thing') to it so I can communicate with it, like if I called a CreateOleObject.

Hope somebody got an answer to it.

Zif.
0
Comment
Question by:ZifNab
  • 7
  • 6
13 Comments
 
LVL 4

Expert Comment

by:jeurk
ID: 1357321
Wow,
I have an answer for the great Zifnab's problem (i hope)
---------------------

Function GetExcelObject:OLEVariant;
Begin
   try
    try
      Result := GetActiveOLEObject('Excel.Application');
    except
      Result := CreateOLEObject('Excel.Application');
    end;
    except on EOleSysError  do
      Result := Unassigned
    end;
end;
------------------------
Procedure CloseExcelObject;
var ExcelObj: OLEVariant;
begin
   //  Close Excel
   ExcelObj := Unassigned ;

    try
      // but only if it's running!
      ExcelObj := GetActiveOLEObject('Excel.Application');

      if fPromptSave then
       ExcelObj.quit (wdPromptToSaveChanges)
       else
       ExcelObj.quit(wdDoNotSaveChanges);

    except  on EOleSysError do
      ExcelObj := Unassigned ;
    end;
End;

I hope this solves your problem.

You can find more stuff in the good mswordmerge component data2wrd.zip on any good
delphi site. it's a component made by pierre@finalfiler.com

Jeurk.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 1357322
Just one more comment :
Zif ! you one of the best expert here should not be able to ask any question
that is worth less then 100 points ;)
50 points is qualifyed as easy, and you can't answer it by yourself ?
----
Zif, this is humour, ok ?
Let me know if it is working.
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1357323
No problem with GOOD humour Jeurk ;-) look at the word 'good', got it? :-))) No really no problem. :-)

The great Zif. By goly... you should see me floating here. I think I'm far not so good of all you guys here. I'm totally not a programmer although I really like it. And I should go learning real programming.

And looking at your solution... Great that I didn't come on that ;-)... well nobody is perfect ;-) ... I try it at home.

Thanks again jeurk.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 1357324
Hi,
is it working ?

0
 
LVL 8

Author Comment

by:ZifNab
ID: 1357325
I'm working on it (haven't had much time). Euhm, do you have the url to data2wrd.zip... can't find it anyware.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 1357326
I sent it to you, if it works.
It should exist similar components for excell.
I saw some sometime.

0
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.

 
LVL 8

Author Comment

by:ZifNab
ID: 1357327
Hi Jeurk, Have you got my e-mail address? Thanks for sending it.

And your answer works!!!!! Thanks a lot !!!!!

Zif.


0
 
LVL 4

Expert Comment

by:jeurk
ID: 1357328
Yeah,
cool ! I knew it will work. I hope you are not at work a 14 july ?
Here in france it's 'férier' (if your .be means something you can read it) and by the
way it's my birthday.
Have you got the file ? If you are writing this some hours later you may not
here you have a link to it if not. (let me know if you got it, I have some mail problems)
http://sunsite.informatik.rwth-aachen.de/delphi/ftp/d30free/data2wrd.zip
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1357329
Happy birthday! hip hip, hip hip, hip hip houray!

Euhm, yes I'm working. Here in Belgium we don't have the 'national country day' at 14 july, so we all have to work.

And congratulations for the world-cup!

Thanks I got the file now.

Enjoy of your free day!

Zif.
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1357330
Hey Jeurk, don't forget to answer the Q in all your feasts.
0
 
LVL 4

Accepted Solution

by:
jeurk earned 50 total points
ID: 1357331
We are the champions , we are the champions...
Of the worldddddd....
CU in another thread.

0
 
LVL 8

Author Comment

by:ZifNab
ID: 1357332
Still feasting? :-)Having another sip of wine?

For others see comments for answers.

c.u. jeurk.
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1357333
Ooops, forgot to grade the question.
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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

864 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

24 Experts available now in Live!

Get 1:1 Help Now