sharief has asked for the wisdom of the Perl Monks concerning the following question:
Can anybody help me with this reply Re: Delete a sheet from Excelwhere should i include the statement "Application. DisplayAlerts = FALSE" it doese not look like perl code so what should i do to disable the confirmation msg when i delete a woksheet from excel via perl
This is my code
use warnings; use Win32::OLE; my $xl = Win32::OLE->new('Excel.Application', 'Quit'); $path ="C:\\Perl\\Copy of path1.xlsx"; my $wb = $xl->Workbooks->Open($path); my @excel_del_sheets = ("Sheet4", "Sheet5", "Sheet6"); for (my $shtNo = $wb->Sheets->{Count}; $shtNo > 0; $shtNo--) { my $shtName = $wb->Sheets($shtNo)->{Name}; if (grep(/^$shtName$/, @excel_del_sheets)) { $wb->Sheets($shtNo)->Delete; } } $wb->{DisplayAlerts}=0; $wb -> Close;
Update: I found i din change the object for calling {DisplayAlerts}=0;thanks to all monks
Udate: When i disabled the alert the deleted excel worksheet din got save its still there only and only the alert msg has got hidden...</p.
Update: I am unable to delete particular worksheets when i delete few sheets manualy its asking me a prompt like "There exists some data on your sheet do you want to permanently delete this sheet" will that be a possibility for not deleting my particular sheets???
My coe again
use warnings; use Win32::OLE; my $xl = Win32::OLE->new('Excel.Application', 'Quit'); $path ="C:\\Perl\\Copy of path1.xlsx"; my $wb = $xl->Workbooks->Open($path); my @excel_del_sheets = ("Sheet4", "Sheet5", "Sheet6"); for (my $shtNo = $wb->Sheets->{Count}; $shtNo > 0; $shtNo--) { my $shtName = $wb->Sheets($shtNo)->{Name}; if (grep(/^$shtName$/, @excel_del_sheets)) { $wb->Sheets($shtNo)->Delete; } } $wb->{DisplayAlerts}=0; $wb->Save(); $wb -> Close;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Delete a sheet in excel
by marto (Cardinal) on Jan 20, 2012 at 10:56 UTC | |
|
Re: Delete a sheet in excel
by marto (Cardinal) on Jan 20, 2012 at 11:24 UTC | |
|
Re: Delete a sheet in excel
by Anonymous Monk on Jan 20, 2012 at 10:21 UTC |