【发布时间】:2018-06-19 00:45:02
【问题描述】:
我正在尝试将数据从 excel 工作簿复制到另一个工作簿,但在尝试复制时出现 HRESULT: 0x800A03EC。
我已经详细阅读并尝试了之前的帖子HRESULT: 0x800A03EC on Worksheet.range中的所有内容
除了在 DCOM 配置中更改 excel 应用程序的属性之外的所有内容(我没有看到 excel 应用程序)
以下是代码,错误以粗体显示。
Imports Excel = Microsoft.Office.Interop.Excel
Dim xlApp As Excel.Application = Nothing
Dim newxlApp As Excel.Application = Nothing
Dim xlWorkBooks As Excel.Workbooks = Nothing
Dim xlWorkBook As Excel.Workbook = Nothing
Dim xlWorkSheet As Excel.Worksheet = Nothing
Dim newxlworkbooks As Excel.Workbook = Nothing
Dim newxlworkbook As Excel.Workbook = Nothing
Dim newxlworksheet As Excel.Worksheet = Nothing
Dim String2Search4 As String = "1000" 'String to search for.
Dim ColumnNumber As Integer = 4
xlApp = CreateObject("Excel.application")
newxlApp = CreateObject("Excel.application")
xlWorkBook = xlApp.Workbooks.Open("C:\spreadseet1.xlsx")
newxlworkbook = newxlApp.Workbooks.Open("C:\spreedsheet2.xlsx")
newxlworksheet = newxlworkbook.Worksheets("Sheet1")
xlWorkSheet = xlWorkBook.Worksheets("Sheet1")
For X As Integer = 1 To xlWorkSheet.Rows.Count Step 1
'check if the cell value matches the search string.
If xlWorkSheet.Cells(X, ColumnNumber).value = String2Search4 Then
MsgBox("Found " & String2Search4 & " in row " & X)
Dim rowfound As String = (X.ToString + ":" + X.ToString)
**xlWorkSheet.Copy(xlWorkSheet.Cells(2, 2), newxlworksheet.Cells(1, 1))**
newxlworkbook.Close()
xlWorkBook.Close()
End If
Next
--谢谢
【问题讨论】:
标签: excel vb.net visual-studio