How to make COPY of Worksheet(1) to some other Worksheet ???

How to make COPY of Worksheet(1) to some other Worksheet ???

am 12.01.2008 22:09:27 von Katja

How to make COPY of Worksheet(1)to some other Worksheet ???

Please Help!


------------------
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on errors...
# get already active Excel application or open new
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
my $Book = $Excel->Workbooks->Open('d:\cgi\work.xls');
my $Sheet = $Book->Worksheets(1);

# How to make COPY of Worksheet(1) to some other Worksheet ???
#

$Book->Save;
------------------

Re: How to make COPY of Worksheet(1) to some other Worksheet ???

am 14.01.2008 11:26:23 von andygpeters

On Jan 12, 9:09=A0pm, "Katja" wrote:
> How to make COPY of Worksheet(1)to some other Worksheet ???
>
> Please Help!
>
> ------------------
> use strict;
> use Win32::OLE qw(in with);
> use Win32::OLE::Const 'Microsoft Excel';
> $Win32::OLE::Warn =3D 3; # die on errors...
> # get already active Excel application or open new
> my $Excel =3D Win32::OLE->GetActiveObject('Excel.Application')
> || Win32::OLE->new('Excel.Application', 'Quit');
> my $Book =3D $Excel->Workbooks->Open('d:\cgi\work.xls');
> my $Sheet =3D $Book->Worksheets(1);
>
> # How to make COPY of Worksheet(1) to some other Worksheet ???
> #
>
> $Book->Save;
> ------------------

I normally record a macro and use what's been generated.
In your case this gives

Sheets("Sheet1").Select
Sheets("Sheet1").Copy Before:=3DSheets(2)

Which translates to something like

$Sheet->Select;
$Sheet->Copy( 'Before' =3D> $Book->Worksheets(2));

Hope this helps.