命名范围vb.net上的System.MissingMemberException

时间:2017-04-08 20:06:31

标签: excel vb.net com vsto implements

我收到一个System.MissingMemberException:'公共成员'控件'在类型'工作表'没找到。'下面代码的WS.Control行上的错误。下面的代码是我能够提出来访问Excel的活动运行实例的唯一解决方案。

    Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet = Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets(1)
    Dim WB As Microsoft.Office.Interop.Excel.Workbook = Globals.ThisAddIn.Application.ActiveWorkbook
    Dim worksheet As Microsoft.Office.Tools.Excel.Worksheet = Globals.Factory.GetVstoObject(NativeWorksheet)
    Dim rangeName As String = "Scope"
    Dim selection As Excel.Range = Globals.ThisAddIn.Application.Selection

    WB.Worksheets.Add()
    Dim WS As Excel.Worksheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet
    WS.Name = "Scope"
    WS.Activate


    selection = WS.Range("A1:C30")
    selection.Activate
    If Not (selection Is Nothing) Then
        Dim namedRange As NamedRange = WS.Controls.AddNamedRange(selection, rangeName)
    End If

如果我使用工作表代替WS,代码工作正常但是,它将命名范围添加到初始工作表中,我希望将命名范围添加到新添加的工作表中。非常感谢您提供任何急需的支持!!

0 个答案:

没有答案