Copy Paste Excel by Powershell
-
I am having the Excel File 1 and Excel File 2 where the contents in the excel file 2 needs to be copied to excel file 1.Whether the copying can be done through the Sheet name ?
I am having this powershell script to copy but the copying is happening but it should happen according to the sheet present.Can any one help on the same ?
$excel=new-object -comobject excel.application;
$excel.visible=$true;
$SourceWorkBook=$Excel.Workbooks.open("$filelocation");
$TargetWorkBook=$excel.workBooks.open("filelocation");
$SourceWorkBook.WorkSheets.item(1).activate();
$SourceRange=$SourceWorkBook.WorkSheets.item(1).range("A2","O2");
$SourceRange.copy() | out-null;
$TargetWorkBook.worksheets.item(1).paste();
$SourceWorkBook.close($false) # close source workbook w/o saving
$TargetWorkBook.close($true) # close and save destination workbook
$excel.quit() -
Can anyone help on the same if not busy ?
-
@lakshmana sorry am very busy....