【发布时间】:2018-03-24 11:30:38
【问题描述】:
如何从 vsto Outlook 插件中搜索 Excel 工作表中的最后一个空单元格?
我有以下代码(未编译)
Imports Excel = Microsoft.Office.Interop.Excel
Dim ExcelApp As New Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelWorkSheet As Excel.Worksheet= ExcelWorkbook.Worksheets(1)
Dim ExcelRange As Excel.Range = ExcelWorkSheet.Range("A1","A600")
Dim currentFind As Excel.Range = Nothing
Dim firstFind As Excel.Range = Nothing
currentFind = ExcelRange.Find("*", , Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, False)
While Not currentFind Is Nothing
' Keep track of the first range you find.
If firstFind Is Nothing Then
firstFind = currentFind
' If you didn't move to a new range, you are done.
ElseIf currentFind.Address = firstFind.Address Then
Exit While
End If
currentFind = ExcelRange.FindNext(currentFind)
End While
ExcelWorkbook.ActiveSheet.range(currentFind).Select()
我已根据 Scott Holtzman 的 cmets 对其进行了更新,但现在我收到一条错误消息:HRESULT: 0x800A03EC
【问题讨论】:
-
请将解决方案作为答案发布,而不是作为问题的更新。这是为了避免对未来的访问者造成混淆。更改并没有完全丢失,您可以在revisions 中获取它们。
标签: visual-studio excel vsto outlook-addin vba