簡體   English   中英

VB.net HRESULT: 0x800A03EC (excel) 復制時

[英]VB.net HRESULT: 0x800A03EC (excel) when Copying

我正在嘗試將數據從 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

- 謝謝

您的復制語法不正確:

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

我有同樣的錯誤,似乎使用了一些等待時間來修復它:

因此,在復制時,請嘗試使用:

System.Threading.Thread.Sleep(100);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM