将数据从100张Excel工作表复制到单张工作表中的问题

时间:2017-11-01 14:56:39

标签: powershell automation excel-2016

我正在使用Powershell脚本将大约5张Excel工作表(作为样本)的数据从A列加载到AL。实际上,我有100张Excel表格,每个文件中有25个标签。

我使用了链接How to use powershell to copy several excel worksheets and make a new one?

它有很大的帮助。但是,第一张纸的数据被复制并输入到新纸张中,但从第二张文件开始,它开始给出如下错误。

第二个循环应该转到新Excel工作表的最后一行(第151行)并粘贴第二个工作表中的数据。但是我遇到错误“无法获取Range类的Select属性”。然后来自第二张的数据永远不会被粘贴。

因此,2张中的5张数据被复制,而其他3张中的剩余数据从未被粘贴到新Excel表上,主要是由于错误“无法获取范围的Select属性类“

收到错误

2nd Loop
151
Unable to get the Select property of the Range class
At C:\Users\Desktop\ExcelCopy_ETC 2.ps1:84 char:51
+ ... t.Range("A$(($objDestExcel.ActiveSheet.UsedRange.Rows|Select -Last 1) ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

2nd Loop
151
2nd Loop
Destination UsedRange Row: - 311
Unable to get the Select property of the Range class
At C:\Users\Desktop\ExcelCopy_ETC 2.ps1:84 char:51
+ ... t.Range("A$(($objDestExcel.ActiveSheet.UsedRange.Rows|Select -Last 1) ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

2nd Loop
Destination UsedRange Row: - 311
Unable to get the Select property of the Range class
At C:\Users\Desktop\ExcelCopy_ETC 2.ps1:84 char:51
+ ... t.Range("A$(($objDestExcel.ActiveSheet.UsedRange.Rows|Select -Last 1) ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
At C:\Users\Desktop\ExcelCopy_ETC 2.ps1:70 char:5
+     $SourceWorksheet = $SourceWorkBook.WorkSheets.item("3. Automation ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

2nd Loop
Destination UsedRange Row: - 311
0

0 个答案:

没有答案