PC Review


Reply
Thread Tools Rate Thread

Copy Visible Sheets to New File

 
 
=?Utf-8?B?VHJvdWJsZWQgVXNlcg==?=
Guest
Posts: n/a
 
      9th Sep 2007
I have a workbook with multiple different views / displays of the sheets
within the file. Most of these pages have deactivate code on the individual
sheets. I need to be able to generically copy the visible sheets to a new
workbook without taking the code with them.

I have tried doing this in an array and can't get it to work, so I am
thinking that I need to move it a page at a time. I (personally) could
probably make this work by hardcoding the move function to run based upon the
selected view, but thought I would see if anyone had a simplier more generic
way to select / move the visible sheets. Thanks in advance.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      9th Sep 2007
Try this

Private Sub MoveVisibleSheets()
Dim dummyName As String

Dim sourceBook As String ' will hold this workbook's name
Dim destBook As String ' will hold name of new book
Dim otherBook As Workbook
Dim ws As Worksheet
Dim sheetCount As Integer ' count of sheets in 'otherBook'

sourceBook = ThisWorkbook.Name

If MsgBox("Are you sure your want to save to new workbook?", _
vbYesNoCancel + vbExclamation) <> vbYes Then
Exit Sub
End If


Application.ScreenUpdating = False
Workbooks.Add 'adds a "Book#" named workbook - # can vary.
destBook = ActiveWorkbook.Name
sheetCount = ActiveWorkbook.Worksheets.Count

dummyName = "dummy to get this to work on all visible sheets"

Set otherBook = Workbooks(destBook)

Workbooks(sourceBook).Activate ' back to this book
For Each ws In ThisWorkbook.Worksheets
If ws.Visible = xlSheetVisible Then
If ws.Name <> dummyName Then
ThisWorkbook.Worksheets(ws.Name).move
after:=otherBook.Worksheets(sheetCount)
sheetCount = sheetCount + 1
End If
End If
Next
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Application.ScreenUpdating = True
' it just ends, you can name save the copy with a name of your choice
' and clean up this one for next time out?
'

End Sub

"Troubled User" wrote:

> I have a workbook with multiple different views / displays of the sheets
> within the file. Most of these pages have deactivate code on the individual
> sheets. I need to be able to generically copy the visible sheets to a new
> workbook without taking the code with them.
>
> I have tried doing this in an array and can't get it to work, so I am
> thinking that I need to move it a page at a time. I (personally) could
> probably make this work by hardcoding the move function to run based upon the
> selected view, but thought I would see if anyone had a simplier more generic
> way to select / move the visible sheets. Thanks in advance.

 
Reply With Quote
 
=?Utf-8?B?VHJvdWJsZWQgVXNlcg==?=
Guest
Posts: n/a
 
      9th Sep 2007
I will try it and get back with you shortly. Thanks for your help.

"Troubled User" wrote:

> I have a workbook with multiple different views / displays of the sheets
> within the file. Most of these pages have deactivate code on the individual
> sheets. I need to be able to generically copy the visible sheets to a new
> workbook without taking the code with them.
>
> I have tried doing this in an array and can't get it to work, so I am
> thinking that I need to move it a page at a time. I (personally) could
> probably make this work by hardcoding the move function to run based upon the
> selected view, but thought I would see if anyone had a simplier more generic
> way to select / move the visible sheets. Thanks in advance.

 
Reply With Quote
 
=?Utf-8?B?VHJvdWJsZWQgVXNlcg==?=
Guest
Posts: n/a
 
      9th Sep 2007
Mike,

A couple of problems. First, it was trying to Move the sheets to the new
location rather than copy. I don't know if this was by design or not. I
changed this part of the code to be Copy.

I ran it with the Copy change and it created the new file, but it took the
deactivate code on the pages with it. This code calls generic functions in
the source heet and thus errors in the new file.

Thoughts?




"Troubled User" wrote:

> I have a workbook with multiple different views / displays of the sheets
> within the file. Most of these pages have deactivate code on the individual
> sheets. I need to be able to generically copy the visible sheets to a new
> workbook without taking the code with them.
>
> I have tried doing this in an array and can't get it to work, so I am
> thinking that I need to move it a page at a time. I (personally) could
> probably make this work by hardcoding the move function to run based upon the
> selected view, but thought I would see if anyone had a simplier more generic
> way to select / move the visible sheets. Thanks in advance.

 
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
Copy Two Visible Ranges (From Two Sheets) To A New Workbook (AlsoWith Two Sheets) septhemis@gmail.com Microsoft Excel Programming 3 30th Jan 2009 04:20 PM
Re: Copy Two Visible Ranges (From Two Sheets) To A New Workbook (AlsoWith Two Sheets) septhemis@gmail.com Microsoft Excel Programming 0 29th Jan 2009 01:35 PM
copy the same raws of all sheets from about a 100 file to a new sheet of a book and save the file attis555@hotmail.com Microsoft Excel Setup 0 14th Mar 2007 02:13 AM
Can I copy just the visible sheets? =?Utf-8?B?VHJlZm9y?= Microsoft Excel Misc 2 3rd Sep 2006 02:31 PM
Copy Visible Sheets into one Workbook =?Utf-8?B?Q2xheQ==?= Microsoft Excel Programming 3 29th Mar 2006 04:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:03 PM.