【问题标题】:VB.net HRESULT: 0x800A03EC (excel) when CopyingVB.net HRESULT: 0x800A03EC (excel) 复制时
【发布时间】: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


    【解决方案1】:

    您的 Copy 语法不正确:

    xlWorkSheet.Cells(2, 2).Copy(newxlworksheet.Cells(1, 1))
    

    【讨论】:

    • 我尝试了建议的代码并收到错误“Range 类的复制方法失败”所以我可能在上游有错误?
    • 看来我之前的语法是复制整张纸,谢谢指正
    【解决方案2】:

    我遇到了同样的错误,似乎使用了一些等待时间修复了它:

    所以在复制的时候,尽量使用:

    System.Threading.Thread.Sleep(100);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多