Thanks for that. I looked in the link and found enum for all objects and thought that may give what I wanted.
Therefore I wrote some Perl (below) to test it.
Unfortunately, the count was always zero no matter how many Excel files were open.
Googling for Excel and Enum, I did find a site where someone was trying gain access to a file by requesting a handle to it.
I thought that this may give what I wanted on the basis that it would only return a handle if the file was there but not opened.
I can easily test if a file is there – if it is not it cannot be open.
This is also in the Perl code below. Unfortunately this did not work either since it always returned a handle and if the file was not open, it opened Excel with a ‘blank’ screen.
Can anyone give me a clue as to what to do next?
use OLE;
use Win32::OLE::Const "Microsoft Excel";
use strict "vars";
my ($Count, $file, $ML);
$Count = Win32::OLE->EnumAllObjects(sub {
my $Object = shift;
my $Class = Win32::OLE->QueryObjectType($Object);
printf "# Object=%s Class=%s\n", $Object, $Class;
});
print "count <$Count>\n";
$file = "C:\\abcd.xlsx";
$ML = Win32::OLE->GetObject($file)
or print "can't get a handle on '$file'";
print "$ML\n";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.