modules removing problem

A

Adax

Hello, I have problem with this code:

For Each objVbc In Workbooks(wb).VBProject.VBComponents
If objVbc.Type > 0 And objVbc.Type < 4 Then
Workbooks(ActiveWorkbook.Name).VBProject.VBComponents.Remove
objVbc
Else
objVbc.CodeModule.DeleteLines
StartLine:=1,Count:=objVbc.CodeModule.CountOfLines
End If
Next objVbc

I have about 30 modules in workbook. Unfortunately, after modules removing
by above code always 2 modules aren't remove. What is the reason? Is it
possibility to refresh collection VBProject.VBComponents after each
removing?
Lines deleting works very well, but I can't remove all modules, please
help me
Greetings, Adax
 
S

Steve Rindsberg

Hello, I have problem with this code:

For Each objVbc In Workbooks(wb).VBProject.VBComponents
If objVbc.Type > 0 And objVbc.Type < 4 Then
Workbooks(ActiveWorkbook.Name).VBProject.VBComponents.Remove
objVbc
Else
objVbc.CodeModule.DeleteLines
StartLine:=1,Count:=objVbc.CodeModule.CountOfLines
End If
Next objVbc

I have about 30 modules in workbook. Unfortunately, after modules removing
by above code always 2 modules aren't remove. What is the reason? Is it
possibility to refresh collection VBProject.VBComponents after each
removing?
Lines deleting works very well, but I can't remove all modules, please
help me
Greetings, Adax

In most cases, when you're removing items from a collection, you want to do
something like:

For x = Collection.Count to 1 Step -1
Collection(x).Delete ' Remove/whatever
Next
 
A

Adax

U¿ytkownik "Steve Rindsberg said:
In most cases, when you're removing items from a collection, you want to
do something like:
For x = Collection.Count to 1 Step -1
Collection(x).Delete ' Remove/whatever
Next

Thanks! Unfortunately, problem is still. But I noticed, that stoping VBA
code after this removing modules part code give good result and theese 2
modules immediately disappear. Wen I don't break VBA code, finaly I have
always 2 don't removed modules. Problem with refresh modules collection?
Removing items from a collection don't help me too. Have You any
suggestions? Please help me! Greetings, Adax
 
S

Steve Rindsberg

Thanks! Unfortunately, problem is still. But I noticed, that stoping VBA
code after this removing modules part code give good result and theese 2
modules immediately disappear. Wen I don't break VBA code, finaly I have
always 2 don't removed modules. Problem with refresh modules collection?
Removing items from a collection don't help me too. Have You any
suggestions? Please help me! Greetings, Adax

I don't have any other ideas, but suggest that you post this also in one of
the Excel groups.
 

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