1

I'm trying to write a code to using VB.Net to delete the Named Range of the activecell. I can't seem to figure out the correct syntax for this. Can someone please help?

        Dim xlApp As Excel.Application

        xlApp = GetObject(, "Excel.Application")

        xlApp.ActiveCell.Name.Name.Delete()

Thanks in advance.

Patrick
  • 212
  • 2
  • 11

1 Answers1

2

The Application.ActiveCell property returns a Range object.

The Range.Name property returns a Name object.

The Name.Name property returns a string.

So, the statement:

xlApp.ActiveCell.Name.Name.Delete()

is trying to call the nonexistent Delete method on a string.

The statement should be:

xlApp.ActiveCell.Name.Delete()

to call the Name.Delete method.

TnTinMn
  • 11,522
  • 3
  • 18
  • 39