Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Copy Worksheet Not the Macros

I'm looking to copy a worksheet from one Workbook to a new workbook,
but I don't want the Macros, Code or Forms to copy. Only the Worksheet
Data. Any ideas?

This is the code I'm currently using to create the new workbook.


Sub CopySheets()

Application.ScreenUpdating = False

Dim ws As Worksheet, fileDate As String, bFirst As Boolean, wbkNew
As Workbook

Application.DisplayAlerts = False

actwb = ActiveWorkbook.Name
fileDate = Format(Date, "mm-dd-yy")

filenm = (fileDate) & ".xls" 'assign the new workbooks names

bFirst = True
For Each ws In ThisWorkbook.Worksheets
Select Case ws.Name
Case "CHIP RESPONSE LOG", "DocuGrab", "CPC PROD LOG",
"MODIFIER_GRID", "TCR PASS", "TCR DENIAL"
'these are the sheets names which shouldn't be copied
Case Else
If bFirst = True Then
ws.Copy
Set wbkNew = ActiveWorkbook
Set VBComps = ActiveWorkbook.VBProject.VBComponents

bFirst = False
'with the first sheet copied, create a new workbook
Else
ws.Copy After:=wbkNew.Sheets(wbkNew.Sheets.Count)
'add subsequent copies to the new workbook
With ActiveWorkbook.VBProject
End If
End Select
Next ws
wbkNew.SaveAs Filename:=(fileDate) & ".xls"
wbkNew.Close

Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Copy Worksheet Not the Macros

This is code I use to clear out all programmatic items from the active
workbook. You might try running it after you've created your new workbook.


''Needs a reference to the VB Extensibility library set:
'' In the VBE select Tools, References and check:
'' "Microsoft Visual Basic for Applications Extensibility 5.3"


'Removes from active workbook all:
''Regular modules
''Class modules
''Userforms
''Code in sheet and workbook modules
''Non built-in references
''Excel 4 macro sheets
''Dialog sheets
Sub RemoveAllCode()
'XL2K+:
Dim VBComp As VBComponent, AllComp As VBComponents, ThisProj As
VBProject
'XL97 & XL2K:
'Dim VBComp As Object, AllComp As Object, ThisProj As Object
Dim ThisRef As Reference, WS As Worksheet, DLG As DialogSheet
If ActiveWorkbook.Name < ThisWorkbook.Name Then
Set ThisProj = ActiveWorkbook.VBProject
Set AllComp = ThisProj.VBComponents
For Each VBComp In AllComp
With VBComp
Select Case .Type
Case vbext_ct_StdModule, vbext_ct_ClassModule,
vbext_ct_MSForm
AllComp.Remove VBComp
Case vbext_ct_Document
.CodeModule.DeleteLines 1, .CodeModule.CountOfLines
End Select
End With
Next
For Each ThisRef In ThisProj.References
If Not ThisRef.BuiltIn Then ThisProj.References.Remove ThisRef
Next
Application.DisplayAlerts = False
For Each WS In Excel4MacroSheets
WS.Delete
Next
For Each DLG In DialogSheets
DLG.Delete
Next
Else
MsgBox "Switch to the workbook to remove code from"
End If
End Sub

--
Jim
wrote in message
oups.com...
| I'm looking to copy a worksheet from one Workbook to a new workbook,
| but I don't want the Macros, Code or Forms to copy. Only the Worksheet
| Data. Any ideas?
|
| This is the code I'm currently using to create the new workbook.
|
|
| Sub CopySheets()
|
| Application.ScreenUpdating = False
|
| Dim ws As Worksheet, fileDate As String, bFirst As Boolean, wbkNew
| As Workbook
|
| Application.DisplayAlerts = False
|
| actwb = ActiveWorkbook.Name
| fileDate = Format(Date, "mm-dd-yy")
|
| filenm = (fileDate) & ".xls" 'assign the new workbooks names
|
| bFirst = True
| For Each ws In ThisWorkbook.Worksheets
| Select Case ws.Name
| Case "CHIP RESPONSE LOG", "DocuGrab", "CPC PROD LOG",
| "MODIFIER_GRID", "TCR PASS", "TCR DENIAL"
| 'these are the sheets names which shouldn't be copied
| Case Else
| If bFirst = True Then
| ws.Copy
| Set wbkNew = ActiveWorkbook
| Set VBComps = ActiveWorkbook.VBProject.VBComponents
|
| bFirst = False
| 'with the first sheet copied, create a new workbook
| Else
| ws.Copy After:=wbkNew.Sheets(wbkNew.Sheets.Count)
| 'add subsequent copies to the new workbook
| With ActiveWorkbook.VBProject
| End If
| End Select
| Next ws
| wbkNew.SaveAs Filename:=(fileDate) & ".xls"
| wbkNew.Close
|
| Application.DisplayAlerts = True
| Application.ScreenUpdating = True
| End Sub
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Copy Worksheet Not the Macros

hi
try this
dir and path you have change.

Sub copy_ActiveSheet()

ActiveSheet.Cells.Copy
Workbooks.Add Template:="Arbeidsbok"
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False


Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "dd-mm-yy")

Set wb = ActiveWorkbook
With wb

.SaveAs "c:\" & strdate & ".xls"

End With


End Sub

regards yngve

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
Macros for Consolidating data in worksheet 1 on worksheet 2 Omokehinde Excel Programming 1 March 4th 12 01:45 PM
Move/Copy Worksheet with Macros Hansplay Excel Discussion (Misc queries) 2 October 9th 09 05:51 PM
Mastersheet to Worksheet data copy - macros? DCT Mvumi School Excel Discussion (Misc queries) 1 June 4th 09 12:10 PM
Macros: can you copy macros from one doc to another? Roady Excel Discussion (Misc queries) 1 June 12th 08 05:47 PM
weird saving of a document with macros resulting with macros being transfered to the copy alfonso gonzales Excel Programming 0 December 12th 04 09:19 PM


All times are GMT +1. The time now is 11:58 PM.

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"