Q:

Setting value of named range in Excel

I apologize if this is a total noob question. I'm in the process of writing an addin for Excel. I have a sub inside class1 that opens an excel file, in this sub I have a reference to sub2 which is below. All I am looking to do is hook into the active instance of Excel, change a named range value and exit. But I keep getting errors no matter which way that I try. Here is what I have. Tell me where I have gone wrong. Forgot to mention, this is in VB.NET.
   Private Sub SetRangeValue(ByVal RangeName As String, ByVal RangeValue As String)
    Dim ExcelApp As Excel.Application
    Dim TheRange As Excel.Range
    Dim TheRangeName As String = ""

    'Hook into running excel instance
    ExcelApp = CType(Marshal.GetActiveObject("Excel.Application"), Excel.Application)

    'First Attempt Here
    TheRange = ExcelApp.ActiveWorkbook.Names.Item(RangeName)
    TheRange.Value = RangeValue

    'Second Attempt
    TheRange = ExcelApp.Range(RangeName)
    TheRange.Value = RangeValue
End Sub

I can't get either one to work. Any help is appreciated.

A:

Finally I got this to work properly.  This is how it needed to work.  Thanks for all the help.
Private Sub SetRangeValue(ByVal RangeName As String, ByVal RangeValue As String)
    Dim ExcelApp As Excel.Application
    'Dim TheRangeObj As Excel.Range
    Dim TheRange As Microsoft.Office.Interop.Excel.Name
    Dim TheRangeName As String = ""

    'Hook into running excel instance
    ExcelApp = CType(Marshal.GetActiveObject("Excel.Application"), Excel.Application)

    TheRange = ExcelApp.ActiveWorkbook.Names.Item(RangeName)
    TheRange.RefersToRange.Value = RangeValue

End Sub

