Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

OLE, Excel

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
ZifNab
Asked:
ZifNab
  • 7
  • 6
1 Solution
 
jeurkCommented:
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
 
jeurkCommented:
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
 
ZifNabAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jeurkCommented:
Hi,
is it working ?

0
 
ZifNabAuthor Commented:
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
 
jeurkCommented:
I sent it to you, if it works.
It should exist similar components for excell.
I saw some sometime.

0
 
ZifNabAuthor Commented:
Hi Jeurk, Have you got my e-mail address? Thanks for sending it.

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

Zif.


0
 
jeurkCommented:
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
 
ZifNabAuthor Commented:
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
 
ZifNabAuthor Commented:
Hey Jeurk, don't forget to answer the Q in all your feasts.
0
 
jeurkCommented:
We are the champions , we are the champions...
Of the worldddddd....
CU in another thread.

0
 
ZifNabAuthor Commented:
Still feasting? :-)Having another sip of wine?

For others see comments for answers.

c.u. jeurk.
0
 
ZifNabAuthor Commented:
Ooops, forgot to grade the question.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now