Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default sheet backup

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 structu=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)


On Mon, 14 Sep 2009 21:21:29 +0100, "sunilpatel"
wrote:

Can someone please helpme.

I need to backup a sheet called "RP LOG" as a new workbook named "RPLOG".
I have 3 essential requirements though.

1. new workbook and sheet must be protected
2. row one which contains buttons linked to macros bust not be copied
3. the vba code copied across must be deleted.

my attempt below has 2 problems
One is that eventhough i delete row 1 the entire new row one acts as if the
buttons are still there (cursor turns to a hand and links to a macro which
is not in the new workbook resulting in an error)
My second problem is how do i delete the vba code on the new sheet.


Sub Backup()
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Copy
ActiveWorkbook.SaveAs "C:\RPLOG"
ActiveSheet.Unprotect "OLDPASSWORD"
Application.EnableEvents = False
Rows(1).Delete
Cells.Select
Selection.Locked = True
ActiveSheet.Protect "NEWPASSWORD"
Workbooks("RPLOG.XLS").Save
Workbooks("RPLOG.XLS").Close
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default sheet backup

"sunilpatel" wrote in message
...
Can someone please helpme.

Please fix your date first.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default sheet backup

Can someone please helpme.

I need to backup a sheet called "RP LOG" as a new workbook named "RPLOG".
I have 3 essential requirements though.

1. new workbook and sheet must be protected
2. row one which contains buttons linked to macros bust not be copied
3. the vba code copied across must be deleted.

my attempt below has 2 problems
One is that eventhough i delete row 1 the entire new row one acts as if the
buttons are still there (cursor turns to a hand and links to a macro which
is not in the new workbook resulting in an error)
My second problem is how do i delete the vba code on the new sheet.


Sub Backup()
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Copy
ActiveWorkbook.SaveAs "C:\RPLOG"
ActiveSheet.Unprotect "OLDPASSWORD"
Application.EnableEvents = False
Rows(1).Delete
Cells.Select
Selection.Locked = True
ActiveSheet.Protect "NEWPASSWORD"
Workbooks("RPLOG.XLS").Save
Workbooks("RPLOG.XLS").Close
End Sub


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 certain cells to a "backup" sheet using VB Chris Excel Programming 3 May 10th 09 04:42 PM
Backup sedgy Excel Discussion (Misc queries) 5 February 6th 09 06:13 PM
backup gall Excel Discussion (Misc queries) 6 August 8th 06 07:22 PM
Backup Alek Excel Discussion (Misc queries) 1 January 8th 06 01:23 AM
backup libby Excel Programming 1 January 14th 04 06:57 AM


All times are GMT +1. The time now is 07:14 AM.

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"