FryGirl
Well-known Member
- Joined
- Nov 11, 2008
- Messages
- 1,376
- Office Version
- 365
- 2016
- Platform
- Windows
I found this code but it doesn't seem to do the trick. I have named ranges both worksheet and workbook level. I need to change all the worksheet level named ranges to workbook.
Code:
[FONT=Times New Roman][SIZE=3][COLOR=#000000]Public SubRescopeNamedRangesToWorksheet()[/COLOR][/SIZE][/FONT]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Dim wb As Workbook[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Dim ws As Worksheet[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Dim objName As Name[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Dim sWsName As String[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Dim sWbName As String[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Dim sRefersTo As String[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Dim sObjName As String[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Set wb = ActiveWorkbook[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Set ws = ActiveSheet[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] sWsName = ws.Name[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] sWbName = wb.Name[/FONT][/COLOR][/SIZE]
[FONT=Times New Roman][SIZE=3][COLOR=#000000] [/COLOR][/SIZE][/FONT]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] For Each objName In wb.Names[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] If objName.Visible = True Then[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] If InStr(1, objName.RefersTo,sWsName, vbTextCompare) Then[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] sRefersTo = objName.RefersTo[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] sObjName = objName.Name[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] If objName.Parent.Name =sWbName Then[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] objName.Delete[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] ws.Names.AddName:=sObjName, RefersTo:=sRefersTo[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] End If[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] End If[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] End If[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][FONT=Times New Roman] Next objName[/FONT][/COLOR][/SIZE]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]