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

0

I have a strange problem with Excel automation in VSTO. The below code works well with English but not with German language. The error is coming from first line of the code below. I get the following error when I watch the execution. Can someone tell me what's going wrong with the language setting.

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
vba
excel
vsto
asked on Stack Overflow Apr 21, 2018 by Raghu • edited Apr 21, 2018 by Raghu

1 Answer

0

It looks like you're using the End property incorrectly. Try removing the references to Excel.XlDirection.

For example, change:

End(Excel.XlDirection.xlDown)  

...to:

End(xlDown)

See the documentation for the property:


If Excel's constants are not recognized, you can either declare them yourself or else substitute the actual values in your code:

XlDirection Enumeration (Excel)

img

answered on Stack Overflow Apr 21, 2018 by ashleedawg • edited Apr 21, 2018 by ashleedawg

User contributions licensed under CC BY-SA 3.0