以下代码是将EXCEL内容复制到WORD,有的EXCEL可以顺利复制粘贴,有的则执行到标红处以后直接报错,麻烦老师看看是不是WS.SELECT及以后的代码有问题?
此主题相关图片如下:3.jpg
For Each file As String In FileSys.GetFiles(path)
If file.EndsWith(".xls") OrElse file.EndsWith(".xlsx") Then
Dim Wb As MSExcel.WorkBook=excelApp.WorkBooks.open(file)
For k As Integer = 1 To Wb.WorkSheets.Count '//多个sheet的处理
msgbox(1)
Dim Ws As MSExcel.WorkSheet=Wb.WorkSheets(k)
msgbox(2)
ws.Select
Dim Rg As MSExcel.Range = Ws.UsedRange
msgbox(3)
If Rg.Columns.Count <> 16384 Then
Rg.copy()
DocRange.Paste
Docrange.Collapse(0)
Docrange.Insertparagraphafter()
Docrange.Collapse(0)
...........