I have a macro that applies protection to ranges in seven worksheets. It gives the ranges a title (required parameter) "Range1"..."Range7".
The problem I have is that if I want to turn the protection off and then reapply it by running the macro again, the macro fails because "Range1"..."Range7" already exist (I get a run-time error "Application-defined or object-defined error").
I can avoid the problem by changing the titles in the macro, e.g. "RangeA"..."RangeG", but this just adds 7 redundant names and next time I want to run the macro again - same problem.
What I therefore want to do is delete the range titles before I re-run the macro. The titles are hidden (not displayed in the Name Manager) and I have tried various combinations of the code below to make them visible without success.
I don't want to delete ALL names, but to be able to select the names I want to delete.
As an alternative, maybe it is possible in the macro to force the range titles to be visible when it creates the ranges? I know it's possible to remove them in the XML, but that seems overkill.
Any help gratefully received!
The problem I have is that if I want to turn the protection off and then reapply it by running the macro again, the macro fails because "Range1"..."Range7" already exist (I get a run-time error "Application-defined or object-defined error").
I can avoid the problem by changing the titles in the macro, e.g. "RangeA"..."RangeG", but this just adds 7 redundant names and next time I want to run the macro again - same problem.
What I therefore want to do is delete the range titles before I re-run the macro. The titles are hidden (not displayed in the Name Manager) and I have tried various combinations of the code below to make them visible without success.
I don't want to delete ALL names, but to be able to select the names I want to delete.
As an alternative, maybe it is possible in the macro to force the range titles to be visible when it creates the ranges? I know it's possible to remove them in the XML, but that seems overkill.
Code:
Sub ShowNames()
Dim xName As Name
For Each xName In Application.ActiveWorkbook.Names
xName.Visible = True
Next xName
End Sub
Any help gratefully received!
Last edited: