Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Variables in $Excel->Workbooks->Open

6 views
Skip to first unread message

Ganesh Babu N

unread,
May 6, 2013, 9:42:46 AM5/6/13
to Perl

Dear All,

I am having an XLSX file in server and my OS in Win7. The first open statement is working fine in which we have give the actual file name.

2nd open function is not working where we have given the file name as variable.

Please help in resolving this error.


use Win32::OLE;
use Win32::OLE qw(in with);
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Excel';
$emfile="02896787";
$Excel = Win32::OLE->GetActiveObject('Excel.Application') ||
       Win32::OLE->new('Excel.Application');
$Excel->{'Visible'} = 0;        #0 is hidden, 1 is visible
$Excel->{DisplayAlerts}=0;    #0 is hide alerts
my $mBook = $Excel->Workbooks->Open
             ('\\\\pchns2003z\SPECIALIZED_SERVICES_I\AnI\Embase\Pull files_IRNPD\inventory\02896787.xlsx'); # open Excel file

my $meBook = $Excel->Workbooks->Open
             ("\\\\pchns2003z\\SPECIALIZED_SERVICES_I\\AnI\\Embase\\Pull files_IRNPD\\inventory\\$emfile.xlsx"); # open Excel file
             
$Sheet2 = $mBook->Worksheets(1);
$Sheet3 = $meBook->Worksheets(1);

Regards,
Ganesh

Jim Gibson

unread,
May 6, 2013, 11:28:42 AM5/6/13
to Perl Beginners
I am not using Windows, but I suggest you try using a single forward slash as a path delimiter for both single and double quotes. I also note that your both of your strings start with '\\\\'. You might try building up the path in a single string variable and use that as the argument to Open, after printing out what the variable actually contains to verify your string is correct.

Rahim Fakir

unread,
May 6, 2013, 3:14:22 PM5/6/13
to Jim Gibson, Perl Beginners
I make promish when i learn to perl, i'll help the more people has possible.
I hope i don't forget!!!!!!!!!!!!!!


--
To unsubscribe, e-mail: beginners-...@perl.org
For additional commands, e-mail: beginne...@perl.org
http://learn.perl.org/



Ganesh Babu N

unread,
May 7, 2013, 4:48:11 AM5/7/13
to Jim Gibson, Perl Beginners
I tried your method but it showing the same error.

Ganesh


Jim Gibson

unread,
May 7, 2013, 10:13:50 AM5/7/13
to Perl Beginners

On May 7, 2013, at 1:48 AM, Ganesh Babu N wrote:

> I tried your method but it showing the same error.

Which method? I made two suggestions. It is always helpful to post the exact program that you tried and the exact error message you are getting. As I explained, I do not have a Windows system on which I can try to reproduce your problem, but others on the list will. You can make it very easy to help you by providing the program so that someone with Windows can try it out on their system and maybe find a solution.

Jenda Krynicky

unread,
Jun 4, 2013, 8:46:10 AM6/4/13
to Perl
There is no problem with the variable interpolation or backslashes.
The two strings are the same:

my $emfile="02896787";

my $mBook =
'\\\\pchns2003z\SPECIALIZED_SERVICES_I\AnI\Embase\Pullfiles_IRNPD\inve
ntory\02896787.xlsx';

my $meBook =
"\\\\pchns2003z\\SPECIALIZED_SERVICES_I\\AnI\\Embase\\Pullfiles_IRNPD\
\inventory\\$emfile.xlsx";

print "$mBook\n$meBook\n";

print ($mBook eq $meBook ? "the same" : "different");


The problem lies elsewhere. If you ask Excel to open the same file in
two instances at the same time it will complain that it's already
open.

Try to open a different file :-)

Jenda
===== Je...@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

0 new messages