ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sheet code module question (https://www.excelbanter.com/excel-programming/306383-sheet-code-module-question.html)

Stuart[_5_]

Sheet code module question
 
A routine runs, whereby the contents of a workbook are copied
to a new workbook. This new workbook contains one single
worksheet. It has no standard modules, and the Thisworkbook
module is empty. However, there is still code in the new sheet's
Sheet module (specifically Worksheet_SelectionChange Event
code).

I understand this cannot be deleted.

If that is the case, can I prevent it being copied into the new
worksheet in the first place?

Regards.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.735 / Virus Database: 489 - Release Date: 06/08/2004



patrick molloy

Sheet code module question
 
Im my example, I'm copying a range called 'Database' from
a sheet called 'main' into a new workbook...

Sub CopySheet()
Dim wb As Workbook
Dim Source As Range
Dim target As Range
Set Source = _
ThisWorkbook.Sheets("main").Range("Database")
Set wb = Workbooks.Add(xlWBATWorksheet)
With wb.ActiveSheet
Set target = .Range(.Range("A1"), _
.Cells(Source.Rows.Count, Source.Columns.Count))
End With

target.Value = Source.Value

End Sub


By just copying the values from the sheet rather than the
sheet itself, we avoid copying any code that is a
attached to the sheet

HTh
Patrick Molloy
Microsoft Excel MVP


-----Original Message-----
A routine runs, whereby the contents of a workbook are

copied
to a new workbook. This new workbook contains one single
worksheet. It has no standard modules, and the

Thisworkbook
module is empty. However, there is still code in the new

sheet's
Sheet module (specifically Worksheet_SelectionChange

Event
code).

I understand this cannot be deleted.

If that is the case, can I prevent it being copied into

the new
worksheet in the first place?

Regards.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system

(http://www.grisoft.com).
Version: 6.0.735 / Virus Database: 489 - Release Date:

06/08/2004


.



All times are GMT +1. The time now is 10:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com