PC Review


Reply
Thread Tools Rate Thread

Copying Range Names to another open workbook

 
 
ll
Guest
Posts: n/a
 
      27th Apr 2007
Hi,
I am trying to copy my range names to another open workbook. I've
been looking at the script below but can't figure out how to get it to
copy the range names from the first (LOldWb) workbook to the second
(LNewWb) workbook. Thanks, Louis
-------------------------

'Define old and new workbooks
Workbooks.Open Filename:=UserForm1.TextBox1.Value
LOldWb = ActiveWorkbook.Name

Workbooks.Add
LNewWb = ActiveWorkbook.Name


'Loop to copy range names from old to new workbooks

For Each x In LOldWb.Names

Workbooks(LNewWb).Names.Add Name:=x.Name, _
RefersTo:=x.Value
Next x

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      27th Apr 2007
II,

give this a try:

'Define old and new workbooks
Dim LOldWb As Workbook
Dim LNewWb As Workbook
Dim x As Name

Set LOldWb = Workbooks.Open(Filename:=UserForm1.TextBox1.Value)
Set LNewWb = Workbooks.Add

'Loop to copy range names from old to new workbooks
For Each x In LOldWb.Names
LNewWb.Names.Add Name:=x.Name, _
RefersTo:=x.RefersTo
Next x



--
Hope that helps.

Vergel Adriano


"ll" wrote:

> Hi,
> I am trying to copy my range names to another open workbook. I've
> been looking at the script below but can't figure out how to get it to
> copy the range names from the first (LOldWb) workbook to the second
> (LNewWb) workbook. Thanks, Louis
> -------------------------
>
> 'Define old and new workbooks
> Workbooks.Open Filename:=UserForm1.TextBox1.Value
> LOldWb = ActiveWorkbook.Name
>
> Workbooks.Add
> LNewWb = ActiveWorkbook.Name
>
>
> 'Loop to copy range names from old to new workbooks
>
> For Each x In LOldWb.Names
>
> Workbooks(LNewWb).Names.Add Name:=x.Name, _
> RefersTo:=x.Value
> Next x
>
>

 
Reply With Quote
 
ll
Guest
Posts: n/a
 
      27th Apr 2007
On Apr 27, 12:10 pm, Vergel Adriano
<VergelAdri...@discussions.microsoft.com> wrote:
> II,
>
> give this a try:
>
> 'Define old and new workbooks
> Dim LOldWb As Workbook
> Dim LNewWb As Workbook
> Dim x As Name
>
> Set LOldWb = Workbooks.Open(Filename:=UserForm1.TextBox1.Value)
> Set LNewWb = Workbooks.Add
>
> 'Loop to copy range names from old to new workbooks
> For Each x In LOldWb.Names
> LNewWb.Names.Add Name:=x.Name, _
> RefersTo:=x.RefersTo
> Next x
>
> --
> Hope that helps.
>
> Vergel Adriano
>
> "ll" wrote:
> > Hi,
> > I am trying to copy my range names to another open workbook. I've
> > been looking at the script below but can't figure out how to get it to
> > copy the range names from the first (LOldWb) workbook to the second
> > (LNewWb) workbook. Thanks, Louis
> > -------------------------

>
> > 'Define old and new workbooks
> > Workbooks.Open Filename:=UserForm1.TextBox1.Value
> > LOldWb = ActiveWorkbook.Name

>
> > Workbooks.Add
> > LNewWb = ActiveWorkbook.Name

>
> > 'Loop to copy range names from old to new workbooks

>
> > For Each x In LOldWb.Names

>
> > Workbooks(LNewWb).Names.Add Name:=x.Name, _
> > RefersTo:=x.Value
> > Next x



Thanks for your help in this - however, it is throwing an error.

Elsewhere in my code, I am getting the 'type mismatch' error on the
following line:
Windows(LOldWb).Activate

Does this need to be simply LOldWb.Activate?

Thanks

 
Reply With Quote
 
ll
Guest
Posts: n/a
 
      27th Apr 2007
On Apr 27, 3:40 pm, ll <barn104_1...@yahoo.com> wrote:
> On Apr 27, 12:10 pm, Vergel Adriano
>
>
>
> <VergelAdri...@discussions.microsoft.com> wrote:
> > II,

>
> > give this a try:

>
> > 'Define old and new workbooks
> > Dim LOldWb As Workbook
> > Dim LNewWb As Workbook
> > Dim x As Name

>
> > Set LOldWb = Workbooks.Open(Filename:=UserForm1.TextBox1.Value)
> > Set LNewWb = Workbooks.Add

>
> > 'Loop to copy range names from old to new workbooks
> > For Each x In LOldWb.Names
> > LNewWb.Names.Add Name:=x.Name, _
> > RefersTo:=x.RefersTo
> > Next x

>
> > --
> > Hope that helps.

>
> > Vergel Adriano

>
> > "ll" wrote:
> > > Hi,
> > > I am trying to copy my range names to another open workbook. I've
> > > been looking at the script below but can't figure out how to get it to
> > > copy the range names from the first (LOldWb) workbook to the second
> > > (LNewWb) workbook. Thanks, Louis
> > > -------------------------

>
> > > 'Define old and new workbooks
> > > Workbooks.Open Filename:=UserForm1.TextBox1.Value
> > > LOldWb = ActiveWorkbook.Name

>
> > > Workbooks.Add
> > > LNewWb = ActiveWorkbook.Name

>
> > > 'Loop to copy range names from old to new workbooks

>
> > > For Each x In LOldWb.Names

>
> > > Workbooks(LNewWb).Names.Add Name:=x.Name, _
> > > RefersTo:=x.Value
> > > Next x

>
> Thanks for your help in this - however, it is throwing an error.
>
> Elsewhere in my code, I am getting the 'type mismatch' error on the
> following line:
> Windows(LOldWb).Activate
>
> Does this need to be simply LOldWb.Activate?
>
> Thanks



I just have gotten this to work. I did simply replace all instances
of Windows(LOldWb) to LOldWb

Thanks again,
Louis

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      27th Apr 2007
Yes, LOldWb.Activate would work.


--
Hope that helps.

Vergel Adriano


"ll" wrote:

> On Apr 27, 12:10 pm, Vergel Adriano
> <VergelAdri...@discussions.microsoft.com> wrote:
> > II,
> >
> > give this a try:
> >
> > 'Define old and new workbooks
> > Dim LOldWb As Workbook
> > Dim LNewWb As Workbook
> > Dim x As Name
> >
> > Set LOldWb = Workbooks.Open(Filename:=UserForm1.TextBox1.Value)
> > Set LNewWb = Workbooks.Add
> >
> > 'Loop to copy range names from old to new workbooks
> > For Each x In LOldWb.Names
> > LNewWb.Names.Add Name:=x.Name, _
> > RefersTo:=x.RefersTo
> > Next x
> >
> > --
> > Hope that helps.
> >
> > Vergel Adriano
> >
> > "ll" wrote:
> > > Hi,
> > > I am trying to copy my range names to another open workbook. I've
> > > been looking at the script below but can't figure out how to get it to
> > > copy the range names from the first (LOldWb) workbook to the second
> > > (LNewWb) workbook. Thanks, Louis
> > > -------------------------

> >
> > > 'Define old and new workbooks
> > > Workbooks.Open Filename:=UserForm1.TextBox1.Value
> > > LOldWb = ActiveWorkbook.Name

> >
> > > Workbooks.Add
> > > LNewWb = ActiveWorkbook.Name

> >
> > > 'Loop to copy range names from old to new workbooks

> >
> > > For Each x In LOldWb.Names

> >
> > > Workbooks(LNewWb).Names.Add Name:=x.Name, _
> > > RefersTo:=x.Value
> > > Next x

>
>
> Thanks for your help in this - however, it is throwing an error.
>
> Elsewhere in my code, I am getting the 'type mismatch' error on the
> following line:
> Windows(LOldWb).Activate
>
> Does this need to be simply LOldWb.Activate?
>
> Thanks
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro in one workbook that names a range in a different workbook Tony Bender Microsoft Excel Programming 2 6th Mar 2009 12:27 AM
COPYING FORMULA CONTAINING NAMES/RELATIVE RANGE NAMES Bricol Microsoft Excel Misc 0 8th Jul 2008 03:54 PM
Copying range from selected workbook to open workbook John Microsoft Excel Programming 2 11th Aug 2007 03:49 PM
RE: Copying a range from one workbook to another workbook =?Utf-8?B?Y2FsZG9n?= Microsoft Excel Programming 0 26th Mar 2006 11:45 PM
Copying Range Names and values from one tab to another Rob Slagle Microsoft Excel Programming 1 9th Aug 2005 07:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:30 AM.