View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Leave 2 macros after copy

Put them in a separate module and skip that module in your code.

Sub AAA()
Set VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
If VBComp.Name < "Module3" Then
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End If
Next VBComp

End Sub

--
Regards,
Tom Ogilvy


"David" wrote in message
...
Each month I backup a workbook with only values intact. As part of that
backup routine, I use the following to strip the backup of ALL code:

Set VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
Next VBComp

Short, concise and non-convoluted.

I've since added a couple of macros that I wish to remain in the backup to
avoid having to later copy/paste them from the original.

Without greatly enlarging the code-stripping routine, can I retain those 2
macros/procedures? I would even entertain putting them in a separate

module
if I knew how to easily strip all the other code out. I have
'ThisWorkbook' code, UserForms and 'Module' code in the original file.

I anticipate the suggestion just to run those two procedures before
performing the backup, but by necessity I need to be able to run them
several days after the backup is performed.

Any help?

--
David