I am receiving a System.MissingMemberException: 'Public member 'Controls' on type 'Worksheet' not found.' error on the WS.Control line of the code below. The code below is the only solution I have been able to come up with to access the active running instance of 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
The code works fine if I use worksheet in place of WS however, it adds the named range to the initial worksheet and I am looking to add the named range to the newly added worksheet. Thank you very much in advance for any much needed support on this!!