提问人:gregor 提问时间:11/9/2023 最后编辑:braXgregor 更新时间:11/9/2023 访问量:47
在 VBA (Word) 中更新模块
Updating Modules in VBA (Word)
问:
例如,我在 Normal 中有 Module1、Module2 和一些 UserForms。我也有模块和表单保存到文件,Module1.bas 和 Module2.bas 等。在运行宏(Macro1 中的过程)期间,我检查 Normal 中的 Module1 版本是否与文件 Module1.bas 中的版本相同,如果不同,我想删除 Module1 和 Module2。问题是我无法删除 Module1,因为我从该模块调用了过程。当宏停止工作时,将删除 Module1。
Private Function RemoveModulesAndForms() As Boolean
Dim component As Object
Dim componentName As String
Dim isComponentRemoved As Boolean
Dim notRemoved() As Variant
Dim i As Integer
Dim isAllRemoved As Boolean
Dim prompt As String
Dim caption_ As String
i = -1
isAllRemoved = True
For Each component In Application.Templates("Normal.dotm").VBProject.VBComponents
componentName = component.name
DoEvents
If componentName <> "ThisDocument" Then
Application.Templates("Normal.dotm").VBProject.VBComponents.Remove component
isComponentRemoved = Not CheckIfComponentExist(componentName)
If isComponentRemoved = False Then
i = i + 1
ReDim Preserve notRemoved(i)
notRemoved(i) = componentName
isAllRemoved = False
End If
End If
Next
prompt = "Components not removed: " + Join(notRemoved, ",")
If isAllRemoved = False Then
MsgBox prompt, vbCritical
End If
RemoveModulesAndForms = isAllRemoved
End Function
有什么建议吗?
答: 暂无答案
评论