Excel VSTO本地化问题。Findnext

Excel VSTO本地化问题。Findnext,excel,localization,vsto,Excel,Localization,Vsto,Excel VSTO解决方案中的.Findnext遇到了一个奇怪的问题。该代码在英语设置下运行良好,但在德语设置下由于以下错误而失败 System.NullReferenceException:“对象引用未设置为对象的实例。” 调查时,EndRng=.FindNext(EndRng)不返回任何内容。这个模块怎么可能在英语环境下工作,而不是在德语环境下工作 Dim StartRng As Excel.Range, EndRng As Excel.Range Dim wrkSheet As Work

Excel VSTO解决方案中的.Findnext遇到了一个奇怪的问题。该代码在英语设置下运行良好,但在德语设置下由于以下错误而失败

System.NullReferenceException:“对象引用未设置为对象的实例。”

调查时,EndRng=.FindNext(EndRng)不返回任何内容。这个模块怎么可能在英语环境下工作,而不是在德语环境下工作

Dim StartRng As Excel.Range, EndRng As Excel.Range
Dim wrkSheet As Worksheet
Dim wb As Excel.Workbook = Globals.ThisAddIn.Application.ActiveWorkbook
Dim xlapp As Excel.Application = Globals.ThisAddIn.Application

Dim FormulaToFind As String = FormulaToLocal(FormulaString)
wrkSheet.Range(wrkSheet.Cells(RowStart, ColStart), wrkSheet.Cells(RowEnd, ColEnd)).Select()       
With xlapp.ActiveWindow.Selection
          StartRng = .Find(FormulaToFind, LookIn:=Excel.XlFindLookIn.xlFormulas, LookAt:=Excel.XlLookAt.xlPart)
          If Not StartRng Is Nothing Then
             EndRng = StartRng
             StartAddress = StartRng.Address
             Do
                EndAddress = EndRng.Address
                EndRng = .FindNext(EndRng)
                Loop While Not EndRng Is Nothing And EndRng.Address <> StartAddress
          End If
      End With

微软承认这方面存在一些问题。他们正在和高级工程师一起调查。下面是微软社区的Andreas建议的替代解决方案

With rngData
    StartRng = .Find(FormulaToFind, LookIn:=Excel.XlFindLookIn.xlFormulas, LookAt:=Excel.XlLookAt.xlPart,
                     SearchOrder:=Excel.XlSearchOrder.xlByRows, SearchDirection:=Excel.XlSearchDirection.xlNext)
    If Not StartRng Is Nothing Then
        EndRng = StartRng
        StartAddress = StartRng.Address
        Do
            EndAddress = EndRng.Address
            EndRng = .Find(FormulaToFind, After:=EndRng, LookIn:=Excel.XlFindLookIn.xlFormulas, LookAt:=Excel.XlLookAt.xlPart,
        SearchOrder:=Excel.XlSearchOrder.xlByRows, SearchDirection:=Excel.XlSearchDirection.xlNext)

        Loop While Not EndRng Is Nothing And EndRng.Address <> StartAddress
    End If
End With
带有rngData的

StartRng=.Find(FormulaToFind,LookIn:=Excel.XlFindLookIn.xlFormulas,LookAt:=Excel.XlLookAt.xlPart,
SearchOrder:=Excel.XlSearchOrder.xlByRows,SearchDirection:=Excel.XlSearchDirection.xlNext)
如果不是开始,那就什么都不是了
EndRng=开始
StartAddress=StartRng.地址
做
EndAddress=EndRng.Address
EndRng=.Find(FormulaToFind,After:=EndRng,LookIn:=Excel.XlFindLookIn.xlFormulas,LookAt:=Excel.XlLookAt.xlPart,
SearchOrder:=Excel.XlSearchOrder.xlByRows,SearchDirection:=Excel.XlSearchDirection.xlNext)
循环而非EndRng为Nothing,EndRng.Address StartAddress为Nothing
如果结束
以

您需要给我们一个例子,我们可以用它来重新编程。什么是
FormulaString
?您确定要从'FormulaToLocal'中获取所需的值吗?@Cindymister FormulaString的值为“=转置(MMULT(V49:X51,转置(C48:E48))”)。函数FormulaToLocal返回“=MTRANS(MMULT(V49:X51,MTRANS(C48:E48))”,这是德语的等价形式。该功能完全按照预期工作。该公式作为矩阵公式在3个连续行中重复。我需要检查公式是否应用了3次。
With rngData
    StartRng = .Find(FormulaToFind, LookIn:=Excel.XlFindLookIn.xlFormulas, LookAt:=Excel.XlLookAt.xlPart,
                     SearchOrder:=Excel.XlSearchOrder.xlByRows, SearchDirection:=Excel.XlSearchDirection.xlNext)
    If Not StartRng Is Nothing Then
        EndRng = StartRng
        StartAddress = StartRng.Address
        Do
            EndAddress = EndRng.Address
            EndRng = .Find(FormulaToFind, After:=EndRng, LookIn:=Excel.XlFindLookIn.xlFormulas, LookAt:=Excel.XlLookAt.xlPart,
        SearchOrder:=Excel.XlSearchOrder.xlByRows, SearchDirection:=Excel.XlSearchDirection.xlNext)

        Loop While Not EndRng Is Nothing And EndRng.Address <> StartAddress
    End If
End With