Solved

OLE, Excel

Posted on 1998-07-08
13
484 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

18 Experts available now in Live!

Get 1:1 Help Now