C
Chip Pearson
Try some code like the following. You'll need a reference to the VBA
Extensibility object library.
Sub AAA()
'!!!! requires a reference to:
' Microsoft Visual Basic for Applications Extensibility 5.3
' In VBA go to the Tools menu, choose References, and then
' select this item in the list.
Dim NewWB As Excel.Workbook
Dim NewWS As Excel.Worksheet
Dim SH As Excel.Shape
Dim OleObj As Excel.OLEObject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
ThisWorkbook.Worksheets("RP Log").Copy
' after the Copy, the newly created
' workbook becomes the Active workbook.
Set NewWB = ActiveWorkbook
Set NewWS = ActiveSheet
' get rid of any shapes and Forms controls
For Each SH In NewWS.Shapes
SH.Delete
Next SH
' get rid of OLE/ActiveX controls
For Each OleObj In NewWS.OLEObjects
OleObj.Delete
Next OleObj
' get rid of VBA code
For Each VBComp In NewWB.VBProject.VBComponents
Set CodeMod = VBComp.CodeModule
Select Case VBComp.Type
Case vbext_ct_Document
With CodeMod
On Error Resume Next
.DeleteLines 1, .CountOfLines
End With
Case Else
VBComp.Collection.Remove VBComp
End Select
Next VBComp
Application.DisplayAlerts = False
NewWB.SaveAs Filename:=ThisWorkbook.Path & "\RPLog.xls"
Application.DisplayAlerts = True
NewWS.Protect ' password:="password"
NewWB.Protect structure:=True, Windows:=True ' ,password:="password"
NewWB.Close savechanges:=True
End Sub
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
Extensibility object library.
Sub AAA()
'!!!! requires a reference to:
' Microsoft Visual Basic for Applications Extensibility 5.3
' In VBA go to the Tools menu, choose References, and then
' select this item in the list.
Dim NewWB As Excel.Workbook
Dim NewWS As Excel.Worksheet
Dim SH As Excel.Shape
Dim OleObj As Excel.OLEObject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
ThisWorkbook.Worksheets("RP Log").Copy
' after the Copy, the newly created
' workbook becomes the Active workbook.
Set NewWB = ActiveWorkbook
Set NewWS = ActiveSheet
' get rid of any shapes and Forms controls
For Each SH In NewWS.Shapes
SH.Delete
Next SH
' get rid of OLE/ActiveX controls
For Each OleObj In NewWS.OLEObjects
OleObj.Delete
Next OleObj
' get rid of VBA code
For Each VBComp In NewWB.VBProject.VBComponents
Set CodeMod = VBComp.CodeModule
Select Case VBComp.Type
Case vbext_ct_Document
With CodeMod
On Error Resume Next
.DeleteLines 1, .CountOfLines
End With
Case Else
VBComp.Collection.Remove VBComp
End Select
Next VBComp
Application.DisplayAlerts = False
NewWB.SaveAs Filename:=ThisWorkbook.Path & "\RPLog.xls"
Application.DisplayAlerts = True
NewWS.Protect ' password:="password"
NewWB.Protect structure:=True, Windows:=True ' ,password:="password"
NewWB.Close savechanges:=True
End Sub
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)