PC Review


Reply
Thread Tools Rate Thread

Copy sheets without macros

 
 
=?Utf-8?B?U3Bpa2U=?=
Guest
Posts: n/a
 
      14th Mar 2007
I am running a workbook as a template that after the various macros have run
copies all the sheets to a new workbook and then saves it down to a new name.
The problem is it copies all the code too, i do not want to copy the code
across. I am using the code as below and would appreciate advice as to how
to stop the code being copied too.

Dim NewWb As Workbook
Dim ws As Worksheet
Dim i As Integer
Dim NumberSheets As Integer


Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlManual

NumberSheets = Sheets.Count

'creates a new wb:
Sheets(Sheets.Count).Copy
Set NewWb = ActiveWorkbook

For i = NumberSheets - 1 To 1 Step -1
ThisWorkbook.Sheets(i).Copy Before:=NewWb.Sheets(1)
Next i
'Replace Formula with Values:
For Each ws In NewWb.Worksheets
ws.Cells.Copy
ws.Cells.PasteSpecial (xlPasteValues)
ws.Select
ws.Cells(1, 1).Select
Next ws
--
with kind regards

Spike
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      14th Mar 2007
Hi Spike

You can delete the code in your sheet modules with Chip's code
http://www.cpearson.com/excel/vbe.htm

This is working OK for the activeworkbook
No reference needed in the example

Read the note on Chip's site about "Trust access to Visual Basic Project"

Public Sub DeleteAllVBA()
Dim VBComp As Object
Dim VBComps As Object
Set VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
Select Case VBComp.Type
Case 1, 3, _
2
VBComps.Remove VBComp
Case Else
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Select
Next VBComp
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Spike" <(E-Mail Removed)> wrote in message news:2A81AAE4-3433-41F9-AEB1-(E-Mail Removed)...
>I am running a workbook as a template that after the various macros have run
> copies all the sheets to a new workbook and then saves it down to a new name.
> The problem is it copies all the code too, i do not want to copy the code
> across. I am using the code as below and would appreciate advice as to how
> to stop the code being copied too.
>
> Dim NewWb As Workbook
> Dim ws As Worksheet
> Dim i As Integer
> Dim NumberSheets As Integer
>
>
> Application.ScreenUpdating = False
> Application.DisplayAlerts = False
> Application.Calculation = xlManual
>
> NumberSheets = Sheets.Count
>
> 'creates a new wb:
> Sheets(Sheets.Count).Copy
> Set NewWb = ActiveWorkbook
>
> For i = NumberSheets - 1 To 1 Step -1
> ThisWorkbook.Sheets(i).Copy Before:=NewWb.Sheets(1)
> Next i
> 'Replace Formula with Values:
> For Each ws In NewWb.Worksheets
> ws.Cells.Copy
> ws.Cells.PasteSpecial (xlPasteValues)
> ws.Select
> ws.Cells(1, 1).Select
> Next ws
> --
> with kind regards
>
> Spike

 
Reply With Quote
 
=?Utf-8?B?U3Bpa2U=?=
Guest
Posts: n/a
 
      14th Mar 2007
Thjank you very much for your help/reply i think in view of Chuip's comments
re virus scanners etc i foresee big probs so think i will just have to live
with it or just copy and paste each sheet.
--
with kind regards

Spike


"Spike" wrote:

> I am running a workbook as a template that after the various macros have run
> copies all the sheets to a new workbook and then saves it down to a new name.
> The problem is it copies all the code too, i do not want to copy the code
> across. I am using the code as below and would appreciate advice as to how
> to stop the code being copied too.
>
> Dim NewWb As Workbook
> Dim ws As Worksheet
> Dim i As Integer
> Dim NumberSheets As Integer
>
>
> Application.ScreenUpdating = False
> Application.DisplayAlerts = False
> Application.Calculation = xlManual
>
> NumberSheets = Sheets.Count
>
> 'creates a new wb:
> Sheets(Sheets.Count).Copy
> Set NewWb = ActiveWorkbook
>
> For i = NumberSheets - 1 To 1 Step -1
> ThisWorkbook.Sheets(i).Copy Before:=NewWb.Sheets(1)
> Next i
> 'Replace Formula with Values:
> For Each ws In NewWb.Worksheets
> ws.Cells.Copy
> ws.Cells.PasteSpecial (xlPasteValues)
> ws.Select
> ws.Cells(1, 1).Select
> Next ws
> --
> with kind regards
>
> Spike

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      14th Mar 2007
You can add a new worksheet each time with code and then copy all cells in this new sheet.
This way you not copy the code

If you need help with the code post back
--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Spike" <(E-Mail Removed)> wrote in message news:F0B70CD7-C49B-4766-BF87-(E-Mail Removed)...
> Thjank you very much for your help/reply i think in view of Chuip's comments
> re virus scanners etc i foresee big probs so think i will just have to live
> with it or just copy and paste each sheet.
> --
> with kind regards
>
> Spike
>
>
> "Spike" wrote:
>
>> I am running a workbook as a template that after the various macros have run
>> copies all the sheets to a new workbook and then saves it down to a new name.
>> The problem is it copies all the code too, i do not want to copy the code
>> across. I am using the code as below and would appreciate advice as to how
>> to stop the code being copied too.
>>
>> Dim NewWb As Workbook
>> Dim ws As Worksheet
>> Dim i As Integer
>> Dim NumberSheets As Integer
>>
>>
>> Application.ScreenUpdating = False
>> Application.DisplayAlerts = False
>> Application.Calculation = xlManual
>>
>> NumberSheets = Sheets.Count
>>
>> 'creates a new wb:
>> Sheets(Sheets.Count).Copy
>> Set NewWb = ActiveWorkbook
>>
>> For i = NumberSheets - 1 To 1 Step -1
>> ThisWorkbook.Sheets(i).Copy Before:=NewWb.Sheets(1)
>> Next i
>> 'Replace Formula with Values:
>> For Each ws In NewWb.Worksheets
>> ws.Cells.Copy
>> ws.Cells.PasteSpecial (xlPasteValues)
>> ws.Select
>> ws.Cells(1, 1).Select
>> Next ws
>> --
>> with kind regards
>>
>> Spike

 
Reply With Quote
 
=?Utf-8?B?U3Bpa2U=?=
Guest
Posts: n/a
 
      15th Mar 2007
Many thanks for that, think i will do it like that
--
with kind regards

Spike


"Ron de Bruin" wrote:

> You can add a new worksheet each time with code and then copy all cells in this new sheet.
> This way you not copy the code
>
> If you need help with the code post back
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Spike" <(E-Mail Removed)> wrote in message news:F0B70CD7-C49B-4766-BF87-(E-Mail Removed)...
> > Thjank you very much for your help/reply i think in view of Chuip's comments
> > re virus scanners etc i foresee big probs so think i will just have to live
> > with it or just copy and paste each sheet.
> > --
> > with kind regards
> >
> > Spike
> >
> >
> > "Spike" wrote:
> >
> >> I am running a workbook as a template that after the various macros have run
> >> copies all the sheets to a new workbook and then saves it down to a new name.
> >> The problem is it copies all the code too, i do not want to copy the code
> >> across. I am using the code as below and would appreciate advice as to how
> >> to stop the code being copied too.
> >>
> >> Dim NewWb As Workbook
> >> Dim ws As Worksheet
> >> Dim i As Integer
> >> Dim NumberSheets As Integer
> >>
> >>
> >> Application.ScreenUpdating = False
> >> Application.DisplayAlerts = False
> >> Application.Calculation = xlManual
> >>
> >> NumberSheets = Sheets.Count
> >>
> >> 'creates a new wb:
> >> Sheets(Sheets.Count).Copy
> >> Set NewWb = ActiveWorkbook
> >>
> >> For i = NumberSheets - 1 To 1 Step -1
> >> ThisWorkbook.Sheets(i).Copy Before:=NewWb.Sheets(1)
> >> Next i
> >> 'Replace Formula with Values:
> >> For Each ws In NewWb.Worksheets
> >> ws.Cells.Copy
> >> ws.Cells.PasteSpecial (xlPasteValues)
> >> ws.Select
> >> ws.Cells(1, 1).Select
> >> Next ws
> >> --
> >> with kind regards
> >>
> >> Spike

>

 
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
in VBA Sheets("mysheet").Copy Before:=Sheets(1) how do i get a reference to the newly created copy of this sheet? Daniel Microsoft Excel Discussion 1 6th Jul 2005 10:05 PM
in VBA Sheets("mysheet").Copy Before:=Sheets(1) how do i get a reference to the newly created copy of this sheet? Daniel Microsoft Excel Worksheet Functions 1 6th Jul 2005 09:57 PM
weird saving of a document with macros resulting with macros being transfered to the copy alfonso gonzales Microsoft Excel Programming 0 12th Dec 2004 09:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:53 PM.