当您不知道范围名称时,从 VB.net 写入 Excel 文件

Writing in an Excel file from VB.net when you don't know the range name

我想使用 row/column 数字而不是范围名称写入 excel。我发现这样做的唯一方法是使用 .Cells 属性 但是当我尝试使用它时总是会收到错误 0x800A03EC。我试图尽可能地简化它,以弄清楚如何让它发挥作用。下面的代码适用于 "test1",当它尝试写入 "test2" 时出现错误。我是 运行 excel 2016 和 W10

上的最新版本 visual studio
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet

xlWorkBook = xlApp.Workbooks.Add
xlApp.Visible = True
xlWorkSheet = xlWorkBook.Sheets("Sheet1")

With xlWorkSheet
    .Range("A1").Value = "test1"
    .Range(.Cells(8, 8)).Value = "test2"
End With

有人可以帮我弄清楚如何修复它或知道其他方法吗?

.Range(.Cells(8, 8)).Value = "test2"

取出.Range()。该行需要的是:

.Cells(8,8).Value = "test2"