On 2002-05-15 04:34, garyrpollitt wrote:
Cheers Mudface
But that means me creating a new macro in the new workbook to import the data. I only want one macro on a spreadsheet and that is in "Test1".
Basically "Test1" imports txt data, creates a graph then saves it as a eg "122340".Test1 closes keeping the original macro with nothing on its sheets. But 122340 now also has the macro.
Hope you understand!!
Gary
As soon as Test1 is saved as 122340 then 122340 gets the focus and I want to delete the Macro on 122340
Hi Gary
You could try this code.
BUT be warned...Backup your Files...this
macro will delete ALL Code and Rferences.
Suggest you Save Copies and test extensively.
Place code in Std Module and call it
when you need. You may need to put in Flags
of some sought to ensure that it doesn't get
called EXCEPT when you want it too.
<pre/>
Sub RemoveAllCode()
On Error Resume Next
'Make reference to Extensibilty Library
ThisWorkbook.VBProject.References.AddFromGuid _
"{0002E157-0000-0000-C000-000000000046}", 4, 0
On Error GoTo 0
Dim VBComp As Object, AllComp As Object, ThisProj As Object
Dim ThisRef As Reference, WS As Worksheet, Dlg As DialogSheet
Set ThisProj = ActiveWorkbook.VBProject
Set AllComp = ThisProj.VBComponents
For Each VBComp In AllComp
With VBComp
Select Case .Type
Case 1, 2, 3
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
End Sub
</pre>