Run time Error 13 Type Mismatch Excel 97

M

Monk

Hello

The following code deletes VBA in the file for users however I get a runtime
error 13 on the following line for those that are still using Excel 97. Is
there code that will work for Excel 97 and later versions or is this a
security setting on 97 which I cannot locate.

Error Line
Set VBComps = ActiveWorkbook.VBProject.VBComponents

Full Code
Dim oSht As Object
Application.DisplayAlerts = False 'suppress delete warning
For Each oSht In Sheets
If Not oSht.Visible Then oSht.Delete
Next
Application.DisplayAlerts = True
Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponents
Set VBComps = ActiveWorkbook.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
End Sub
 
P

Peter T

Sounds like your project has a reference set to the wrong Extensibility
library. Remove it form tools/refs. You could add the correct reference,
Vbeext1.olb. However for your procedure I wouldn't bother and adapt to Late
Binding

Change the two declarations starting As VBIDE. to As Object and change the
first Case line to
Case 1 To 3

If interested I have a little routine that I keep in my Personal that will
ensure the correct reference is applied in respect to version.

Regards,
Peter T
 
M

Monk

Thanks Peter. Your suggestions work perfectly.

Peter T said:
Sounds like your project has a reference set to the wrong Extensibility
library. Remove it form tools/refs. You could add the correct reference,
Vbeext1.olb. However for your procedure I wouldn't bother and adapt to Late
Binding

Change the two declarations starting As VBIDE. to As Object and change the
first Case line to
Case 1 To 3

If interested I have a little routine that I keep in my Personal that will
ensure the correct reference is applied in respect to version.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top