Adding Named Range reference in VBA

544 views Asked by At

I am trying to add a string to a named range's Refersto value. The issue is that the string has to being with a "=" to be used with another internal tool. I can create the string easily, but i get the error attached when I try to add the reference. Is there any way to override the error, and place the string having a "=" at the start of the string. A VERY simplified mocked up example is below:

Public Sub AddReference() 

    ActiveWorkbook.Names.Add Name:="DG_PRINT_SETTINGS_001", RefersTo:="={""""001"""",""""print_settings""""}"

End Sub

Any help to make this work would be great as I can't change the other end of the process, I need to shoehorn this to work. I know its possible beacuse its done elsewhere, but the guy who wrote the code is no longer around and I can't ask him...I am kinda SOL

enter image description here

1

There are 1 answers

7
cyboashu On BEST ANSWER

You need to mind the string quotes "

This will work :

 ActiveWorkbook.Names.Add Name:="DG_PRINT_SETTINGS_002", RefersTo:="={""001"",""print_settings""}"

enter image description here