PDA

View Full Version : [SOLVED:] Re allocate Named Range addresses



RINCONPAUL
07-31-2017, 01:07 PM
I've downloaded a file and saved it as a new title in a different directory. However the macros aren't working and I figure it's because all (100 ) of the Named Ranges addresses still refer to the original workbook. Is there a macro that can update all existing Named Ranges to refer to new workbook? This is a typical Named Range address:

=OFFSET('C:\Users\paul\Downloads\[BetAngel1.xlsm]ChartView'!$YU$21,,,COUNT('C:\Users\paul\Downloads\[BetAngel1.xlsm]ChartView'!$YU$21:$YU$2000))

The new address is 'D:\Gruss\Gruss Have A Go.xlsm'

Thanks

mdmackillop
07-31-2017, 01:29 PM
Try

Sub Test()
oldpth = "C:\Users\paul\Downloads\[BetAngel1.xlsm]"
newpth = "D:\Gruss\[Gruss Have A Go.xlsm]"


For Each nm In ActiveWorkbook.Names
x = nm.RefersTo
x = Replace(x, oldpth, newpth)
nm.RefersTo = x
Next
End Sub

RINCONPAUL
07-31-2017, 01:44 PM
Hi md. Get an error '1004' "The syntax of the name isn't correct. Verify that the name: -Starts with a letter or underscore (_); -Doesn't include a space or character that isn't allowed;-Doesn't conflict with an existing name in the workbook."

The debugger has highlighted the line: "nm.RefersTo = x"

mdmackillop
07-31-2017, 01:58 PM
Check x in the immediate window for original and new values and compare details. Watch for apostrophes.
Also
Create a name link to the new location and check the syntax

RINCONPAUL
07-31-2017, 02:41 PM
OK, I'll check that, but have to go to work, so get back later.
Cheers

RINCONPAUL
08-01-2017, 11:54 AM
Not saying your code isn't correct md but I think there's a conflict with an existing name in the workbook? I'll have to retrace my steps on this one, but thanks for your help as always.