Remove VBE Component failed

H

huyeote

Gurus,

I have a procedure to delete all existing modules from a chosen
workbook if the type of the component is not vbext_ct_Document. The
extract of the code is here:

'--- code starts here -----------------------------
Set VBProjTo = xlbk.VBProject

With VBProjTo
For Each VBComp In .VBComponents
If VBComp.Type <> vbext_ct_Document
Then
.VBComponents.Remove VBComp

End If

Next VBComp

End With 'vbprojto

'--- code ends above ------------------------------

I found the code works fine in some workbooks but in others a few
modules may still remains in the project after the code run. Anyone
has any idea why some modules can't be removed?

Thanks,

Huyeote
 
J

Jim Rech

Looks like it should work. The next step is to step through the code and
see why it doesn't. No chance the module remaining is the one with this
code in it right?

--
Jim
| Gurus,
|
| I have a procedure to delete all existing modules from a chosen
| workbook if the type of the component is not vbext_ct_Document. The
| extract of the code is here:
|
| '--- code starts here -----------------------------
| Set VBProjTo = xlbk.VBProject
|
| With VBProjTo
| For Each VBComp In .VBComponents
| If VBComp.Type <> vbext_ct_Document
| Then
| .VBComponents.Remove VBComp
|
| End If
|
| Next VBComp
|
| End With 'vbprojto
|
| '--- code ends above ------------------------------
|
| I found the code works fine in some workbooks but in others a few
| modules may still remains in the project after the code run. Anyone
| has any idea why some modules can't be removed?
|
| Thanks,
|
| Huyeote
 
H

huyeote

Thanks Jim,

I used F8 to step through the code and watch the changes in VBE's
Project Explorer windows and found my code worked in some workbooks.
However in some other workbooks the wierd thing is the module still
remained after getting past the .Remove method and no error was
reported. And then a new module with the same name and indexation (eg.
module1 or module2) was injected after the execution of importing code
from a temp file which was not quoted here.

A possible bug in VBA?

Huyeote
 

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

Top