Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy worksheet excluding defined name ranges

Hi,

I am really struggling with this and would appreciate some assistance.

What I am trying to do is to copy a worksheet from one workbook to
another. The thing is that both workbooks contain defined names and I
do not want the defined names to follow the sheet when it is copied to
the other workbook. Is there any macro that would either exclude the
defined names in the process of copying the sheet or delete all local
names after the sheet has been copied? Both alternatives would work
for me.

Really hoping to get some help on this!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Copy worksheet excluding defined name ranges


most likely you want:

KEEP local names
KILL global names...

I've done it via a temporary copy
to a new workbook.


just play with following:
set the mode const to the option you want...

Sub CopySheetSansNames()
Dim wkb(0 To 2) As Workbook, n As Long

Const mode = 1 'testing GLOBAL names

Set wkb(1) = ThisWorkbook
Set wkb(2) = Workbooks("foo2.xls")

'Copy to a new workbook
wkb(1).Worksheets(1).Copy
Set wkb(0) = ActiveWorkbook

'add an extra sheet so you can delete duplicate
'local/global names
wkb(0).Worksheets.Add after:=wkb(0).Sheets(1)

With wkb(0).Names

Select Case mode
Case 0
'deleting ALL names
For n = .Count To 1 Step -1
.Item(n).Delete
Next
Case 1
'Deleting GLOBAL names
For n = .Count To 1 Step -1
If InStr(.Item(n).Name, "!") = 0 Then .Item(n).Delete
Next
Case 2
'Deleting LOCAL names
For n = .Count To 1 Step -1
If InStr(.Item(n).Name, "!") 0 Then .Item(n).Delete
Next
End Select

End With
wkb(0).Worksheets(1).Copy after:=wkb(2).Sheets(wkb(2).Sheets.Count)
wkb(0).Close 0

End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Thomas Smith wrote :

Hi,

I am really struggling with this and would appreciate some assistance.

What I am trying to do is to copy a worksheet from one workbook to
another. The thing is that both workbooks contain defined names and I
do not want the defined names to follow the sheet when it is copied to
the other workbook. Is there any macro that would either exclude the
defined names in the process of copying the sheet or delete all local
names after the sheet has been copied? Both alternatives would work
for me.

Really hoping to get some help on this!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy worksheet excluding defined name ranges

"keepITcool" wrote in message oft.com...
most likely you want:

KEEP local names
KILL global names...

I've done it via a temporary copy
to a new workbook.


just play with following:
set the mode const to the option you want...

Sub CopySheetSansNames()
Dim wkb(0 To 2) As Workbook, n As Long

Const mode = 1 'testing GLOBAL names

Set wkb(1) = ThisWorkbook
Set wkb(2) = Workbooks("foo2.xls")

'Copy to a new workbook
wkb(1).Worksheets(1).Copy
Set wkb(0) = ActiveWorkbook

'add an extra sheet so you can delete duplicate
'local/global names
wkb(0).Worksheets.Add after:=wkb(0).Sheets(1)

With wkb(0).Names

Select Case mode
Case 0
'deleting ALL names
For n = .Count To 1 Step -1
.Item(n).Delete
Next
Case 1
'Deleting GLOBAL names
For n = .Count To 1 Step -1
If InStr(.Item(n).Name, "!") = 0 Then .Item(n).Delete
Next
Case 2
'Deleting LOCAL names
For n = .Count To 1 Step -1
If InStr(.Item(n).Name, "!") 0 Then .Item(n).Delete
Next
End Select

End With
wkb(0).Worksheets(1).Copy after:=wkb(2).Sheets(wkb(2).Sheets.Count)
wkb(0).Close 0

End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam

Thanks for your quick answer!

I managed to work out a short code string that actually handled what I
was striving for:

Dim MyName As Name
On Error Resume Next
For Each MyName In Worksheets("Sheet1").Names
MyName.Delete
Next MyName

This will delete all local names in Sheet1 which was what I needed.

Thanks again for your help!
//Thomas
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to copy a worksheet containing named ranges to anotherworksheet cil9mxm Excel Worksheet Functions 1 December 3rd 08 06:06 PM
Copy worksheet ranges from One Workbook to another from halem2 Excel Worksheet Functions 0 March 24th 06 01:42 PM
Copy Worksheet plus ranges Ray Batig Excel Programming 2 March 16th 05 10:56 PM
Application-defined or object-defined error on copy Josh Sale Excel Programming 1 February 3rd 05 01:40 AM
Copy ranges of data from Master worksheet. Thanks [email protected] Excel Programming 4 November 24th 03 03:28 AM


All times are GMT +1. The time now is 01:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"