Radical Dylan
New Member
- Joined
- Nov 21, 2011
- Messages
- 6
I am writing a Macro that essentially makes a copy of the spreadsheet I am working on, removes all the macros in the background, and then saves it to a specific folder.
The entire macro works perfectly on excell 2003, but in 2007 and 2010 there is an error in the section below. Does anyone have any ideas why? All help is appreciated, I had been trying to figure it out by myself all weekend.
The entire macro works perfectly on excell 2003, but in 2007 and 2010 there is an error in the section below. Does anyone have any ideas why? All help is appreciated, I had been trying to figure it out by myself all weekend.
Code:
Dim vFilename As Variant
Dim wbActiveBook As Workbook
Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponents
'Get a filename to save as
'FolderName, Project, and Residence are all variables set earlier in the code.
ChDrive FolderName
ChDir FolderName
vFilename = FolderName & "\" & project & "_PI Sheet - " & residence & ".xls"
ActiveWorkbook.SaveCopyAs vFilename
Set wbActiveBook = Workbooks.Open(vFilename)
Set VBComps = wbActiveBook.VBProject.VBComponents
For Each VBComp In VBComps
Select Case VBComp.Type
Case vbext_ct_StdModule, vbext_ct_MSForm, _
vbext_ct_ClassModule
VBComps.Remove VBComp
Case Else
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Select
Next VBComp