Solved

OLE, Excel

Posted on 1998-07-08
13
500 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

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…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

632 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