D
Diehard
Hi
I have a VBAProject that deletes a macro in Office 2000 and is working
well.
My production server has Office 2003 and I'm using the same
VBAProject, but it does not work in Office 2003. I get an error that
my VBAProject does not have VBComponets or it is protected.
See code:
Private Sub RemoveAllMacros(ByVal objDocument Object)
Dim i As Long, l As Long
If objDocument Is Nothing Then Exit Sub
i = 0
On Error Resume Next
i = objDocument.VBProject.VBComponents.Count
On Error GoTo 0
If i < 1 Then ' no VBComponents or protected VBProject
Exit Sub
End If
With objDocument.VBProject
For i = .VBComponents.Count To 1 Step -1
On Error Resume Next
.VBComponents.Remove .VBComponents(i)
' delete the component
On Error GoTo 0
Next i
End With
With objDocument.VBProject
For i = .VBComponents.Count To 1 Step -1
l = 1
On Error Resume Next
l = .VBComponents(i).CodeModule.CountOfLines
.VBComponents(i).CodeModule.DeleteLines 1, l
' clear lines
On Error GoTo 0
Next i
End With
End Sub
I'm I missing something in Office 2003? I also set the security level
in Excel to Medium then Low.
Help, Help!!!
I have a VBAProject that deletes a macro in Office 2000 and is working
well.
My production server has Office 2003 and I'm using the same
VBAProject, but it does not work in Office 2003. I get an error that
my VBAProject does not have VBComponets or it is protected.
See code:
Private Sub RemoveAllMacros(ByVal objDocument Object)
Dim i As Long, l As Long
If objDocument Is Nothing Then Exit Sub
i = 0
On Error Resume Next
i = objDocument.VBProject.VBComponents.Count
On Error GoTo 0
If i < 1 Then ' no VBComponents or protected VBProject
Exit Sub
End If
With objDocument.VBProject
For i = .VBComponents.Count To 1 Step -1
On Error Resume Next
.VBComponents.Remove .VBComponents(i)
' delete the component
On Error GoTo 0
Next i
End With
With objDocument.VBProject
For i = .VBComponents.Count To 1 Step -1
l = 1
On Error Resume Next
l = .VBComponents(i).CodeModule.CountOfLines
.VBComponents(i).CodeModule.DeleteLines 1, l
' clear lines
On Error GoTo 0
Next i
End With
End Sub
I'm I missing something in Office 2003? I also set the security level
in Excel to Medium then Low.
Help, Help!!!