Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copy sheets in workbook to new workbook


This macro is to copy a wb, sheet by sheet into a new blank wk, without
formulas.
I doing this as each page have several formulas and are sheet
protected.


What happens is that the macro so everything correct, except that it
pasts blank sheets.

Please help

Macro:


Sub Copywkbookvalues()
Dim Morg
Dim Mto
Dim tWbk As Workbook
Dim cWbk As Workbook
Dim Sht As Worksheet

Set tWbk = ActiveWorkbook

Workbooks.Add
ActiveWorkbook.SaveAs Filename:= _
"X:\Users\Shared\GENERAL\Christian S\05.11.23 - Budget
Uploading LBUD3\BFR\Copy of file.xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


Set cWbk = ActiveWorkbook


On Error Resume Next
tWbk.Activate
For Each Sht In Worksheets
Sht.Select
Sht.Cells.Select
Selection.Copy
cWbk.Sheets.Add
ActiveSheet.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False



Next


End Sub


--
Ctech
------------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...o&userid=27745
View this thread: http://www.excelforum.com/showthread...hreadid=487689

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default copy sheets in workbook to new workbook

Hi Ctech,

The problem is he
For Each Sht In Worksheets
Sht.Select
Sht.Cells.Select
Selection.Copy
cWbk.Sheets.Add '<<<<<< THIS STEP CANCELS THE CUTCOPYMODE
ActiveSheet.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Next

Any worksheet addition should be done before the copy.

I've sketched out the following which I hope will work for you:
Sub CopyWB_ValOnly()
Dim tWbk As Workbook, cWbk As Workbook, Sht As Integer
On Error GoTo CopyWB_ValOnlyERROR
Set tWbk = ActiveWorkbook
'CREATE WORKBOOK WITH ONE WORKSHEET
Set cWbk = Workbooks.Add(xlWBATWorksheet)
For Sht = 1 To tWbk.Worksheets.Count 'ALIGN WORKSHEETS COUNT
With cWbk
If .Worksheets.Count < Sht Then
.Worksheets.Add
ActiveSheet.Move _
after:=Worksheets(.Worksheets.Count)
End If
End With
Next
For Sht = 1 To tWbk.Worksheets.Count 'COPY WS NAMES AND VALUES
With cWbk
.Worksheets(Sht).Name = tWbk.Worksheets(Sht).Name
tWbk.Worksheets(Sht).Cells.Copy
.Worksheets(Sht).Cells(1, 1).PasteSpecial _
Paste:=xlValues, Operation:=xlNone
End With
Next
cWbk.SaveAs Filename:="X:\Users\Shared\GENERAL\Christian" & _
"S\05.11.23 - Budget Uploading LBUD3\BFR\Copy of file.xls"
Set tWbk = Nothing: Set cWbk = Nothing
Exit Sub
CopyWB_ValOnlyERROR:
cWbk.Close SAVECHANGES:=False
Set tWbk = Nothing: Set cWbk = Nothing
MsgBox "Error in CopyWB_ValOnly routine"
End Sub

Best Regards,
Walt Weber

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
copy all sheets to a new workbook futbol Setting up and Configuration of Excel 3 November 16th 07 12:09 PM
Copy several sheets from one workbook into another at the same tim WiFiMike2006 Excel Discussion (Misc queries) 2 February 8th 07 08:36 PM
copy workbook sheets? L. Setting up and Configuration of Excel 3 November 29th 05 03:30 AM
Copy 1-4 sheets to a new workbook ole_ Excel Programming 3 June 30th 05 11:11 AM
copy a workbook from other workbook with lot of sheets wit... Vai Excel Discussion (Misc queries) 1 January 3rd 05 10:27 PM


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

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

About Us

"It's about Microsoft Excel"