#!/usr/bin/perl use warnings; use strict; use Win32::OLE; sub PrintExcelSheet($); sub WelcheDatei($); my $pfad = "C:\\Lokale_Daten"; opendir(my $fhDir, $pfad) or die $!; my @files = grep { $_ =~ m/\.xls$/ } readdir($fhDir); closedir($fhDir) or die $!; WelcheDatei($pfad); sub WelcheDatei($) { my $pfad = shift; print "Welche der Dateien soll verwendet werden?: "; chomp(my $antw = ); exit if not $antw; for my $i ( 1 .. 31 ) { my $dateiXls = $pfad."/".$i.".xls"; PrintExcelSheet($dateiXls) if $antw eq $i; } # for WelcheDatei($pfad); } # WelcheDatei sub PrintExcelSheet($) { my $dateiXls = shift; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; my $excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $book = $excel->Workbooks->Open("$dateiXls"); $book->Worksheets(2)->PrintOut; $excel->Quit(); } # PrintExcelSheet