VBA For copy Named Range (template) to another workbook

MarcMermans

New Member
Joined
Dec 4, 2012
Messages
7
Hello,

Is i't possible to copy named ranges from one workbook to an other workbook.

The first workbook contains a lot of named ranges and called template. The second workbook has the same structure but not all te named ranges are defined. With a VBA i would like to copy the template to the the second workbook and keep the data, but add the missing named ranges.

I have one template and hunderds of workbooks (xls) that must be modified. Beside that I have 100 different templates each with hunderdsd of workbooks.

Haven any one a idea to do this with a VBA procedure.


Thanks in advance,

Marc
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hello,

Is i't possible to copy named ranges from one workbook to an other workbook.

The first workbook contains a lot of named ranges and called template. The second workbook has the same structure but not all te named ranges are defined. With a VBA i would like to copy the template to the the second workbook and keep the data, but add the missing named ranges.

I have one template and hunderds of workbooks (xls) that must be modified. Beside that I have 100 different templates each with hunderdsd of workbooks.

Haven any one a idea to do this with a VBA procedure.


Thanks in advance,

Marc
This should replicate both local (sheet-level) and global (workbook-level) names and addresses from a "source" workbook to a "receiver" workbook provided the same sheets exist in both. The code goes into a standard module in the source workbook.
Rich (BB code):
Sub ReplicateNamedRanges()
Dim Ws As Workbook 'The source wkbk
Dim Wr As Workbook 'The receiver wkbk
Dim nm As Name
Set Ws = ThisWorkbook
Set Wr = Workbooks("Name of receiver workbook & .file extension here")
For Each nm In Ws.Names
    nam = nm.Name
    adr = nm.RefersTo
    With Wr
        On Error Resume Next
        Names.Add nam, adr
        On Error GoTo 0
    End With
Next nm
End Sub
 
Upvote 0
Marc,

Yes it is possible.

As a basic starting point for you, if you have your 'template' workbook open and run the following code from another open workbook it should copy across the named ranges form template.

Code:
Sub GetNames()
Set wbTemp = Workbooks("template")
For Each Name In wbTemp.Names
ThisWorkbook.Names.Add Name:=Name.Name, RefersTo:=Name   'Assumes all to be Workbook Scope
Next Name
End Sub

Given the scale of your template and workbook numbers you will probably want to further automate the process.

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,222,827
Messages
6,168,482
Members
452,192
Latest member
FengXue

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top