VbComponents.Remove doesn't always remove module

后端 未结 8 818
我寻月下人不归
我寻月下人不归 2021-01-02 01:01

I\'m trying to use Chip Pearson\'s code for overwriting an existing VBA code module with an import from another project. Original code here.

The particular section

相关标签:
8条回答
  • 2021-01-02 01:20

    I have ran into things like this before. The 'DoEvents' command often helps. Have you given that a shot?

    Other times, I have placed the command in a do while loop and used a boolean to continually check if the command in question has succeeded. Including the DoEvents command in the loop is sometimes needed.

    Just remember to put something in the loop so that after so many cycles it will give up. Getting stuck in an infinite loop can be pesky.

    0 讨论(0)
  • 2021-01-02 01:21

    I tried the renaming and found that it caused problems with the sheet modules and ThisWorkbook. So I modified it slightly to rename only the non document modules. This seems to work cleanly.

            If .Item(ModuleName).Type <> vbext_ct_Document Then
                .Item(ModuleName).Name = ModuleName & "_OLD"
                .Remove .Item(ModuleName & "_OLD")
            Else
                .Remove .Item(ModuleName)
            End If
    
    0 讨论(0)
提交回复
热议问题