LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Peter T's Copy WorkBook Contents Copy

Last month, Peter T posted the macro below.

The intention of this macro:
To copy the contents (including formatting) of each worksheet in a
workbook, to another workbook, and to carry out this copy in such a way
that file corruption is not transferred along with the copy.

The macro works, but there are two glitches that I'm sure would be easy
to fix by someone who knew were doing! :)

1. In the original workbook, there are formulas which refer to cells in
other sheets. After the copy, these formulae refer back to the original
workbook; they aren't local to the new workbook.

2. Page Setup information isn't transferred (several of my worksheets,
but not all, have different Page Sizes, Orientations, and Scales. There
are no headers and footers.

Thanks in advance!

Darren
Peter T's Macro:

Sub WorkBookCopy()
Dim i As Long
Dim ws As Worksheet
Dim wbOrig As Workbook
Dim wbNew As Workbook
Dim nm As Name
Dim nmNew
Dim wsNew As Worksheet

Application.Calculation = xlCalculationManual
Set wbOrig = ThisWorkbook
Application.SheetsInNewWorkbook = 1
Set wbNew = Workbooks.Add
Application.SheetsInNewWorkbook = 3

For Each ws In wbOrig.Worksheets
i = i + 1
If i = 1 Then
wbNew.Worksheets(1).Name = ws.Name
Else
wbNew.Worksheets.Add(after:=wbNew.Worksheets(i - 1)).Name =
ws.Name
End If
Next

With wbNew.Names
' if not 100% sure the nm.RefersTo string is less than 255
' don't use this (could be a lot more work involved)
For Each nm In wbOrig.Names
.Add nm.Name, nm.RefersTo
Next
End With

Application.DisplayAlerts = False
i = 0
With wbNew
For Each ws In wbOrig.Worksheets
i = i + 1
ws.Cells.Copy .Worksheets(i).Cells
Next
End With

Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic

End Sub

Darren
 
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
copy entire contents worksheet into new workbook, link but editabl ellyk Excel Discussion (Misc queries) 0 May 12th 10 08:49 PM
Question for Peter T - Copy Paste controls at runtime Geoff Excel Programming 6 November 12th 06 08:05 PM
how do I copy the contents of a cell from one workbook to another Edith F Excel Worksheet Functions 1 May 19th 05 04:51 PM
Does anyone have a copy of the Peter Noneley: Function list? Marc New Users to Excel 1 December 6th 04 08:52 PM
Using VB copy contents of a macro to workbook jminu_2k Excel Programming 2 September 7th 04 10:11 AM


All times are GMT +1. The time now is 09:11 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"