Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

OLE, Excel

Posted on 1998-07-08
13
Medium Priority
?
507 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
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.

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

670 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