错误BC30560:' XlDirection'在名称空间&Microsoft.Office.Interop.Excel中是不明确的

时间:2018-04-21 09:20:39

标签: excel vba excel-vba vsto

我在VSTO中的Excel自动化有一个奇怪的问题。以下代码适用于英语,但不适用于德语。错误来自下面代码的第一行。当我观察执行时,我收到以下错误。有人能告诉我语言设置出了什么问题。

error BC30560: 'XlDirection' is ambiguous in the namespace 'Microsoft.Office.Interop.Excel'.

{System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->  
System.Runtime.InteropServices.COMException: Old format or invalid type library. (Exception from HRESULT: 0x80028018  
(TYPE_E_INVDATAREAD))  
   --- End of inner exception stack trace ---  
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[]
byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs,
ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Dynamic.IDispatchComObject.GetMembers(IEnumerable`1 names)}
wrkSheet.Range(wrkSheet.Range(IDTable), _
    wrkSheet.Range(IDTable).End(Excel.XlDirection.xlToRight) _
    .End(Excel.XlDirection.xlDown)).Select()

Dim rngData As Excel.Range = Globals.ThisAddIn.Application.Selection
With rngData
    StartRng = .Find(FormulaString, LookIn:=Excel.XlFindLookIn.xlFormulas)
    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

1 个答案:

答案 0 :(得分:0)

您似乎错误地使用了End属性。请尝试删除对Excel.XlDirection

的引用

例如,更改:

End(Excel.XlDirection.xlDown)  

......来:

End(xlDown)

请参阅该属性的文档:

如果无法识别Excel的常量,您可以自己声明它们,也可以替换代码中的实际值:

XlDirection枚举(Excel)

img