【发布时间】:2019-06-25 07:24:48
【问题描述】:
我正在尝试设置一个导入模块,如果它满足条件,我需要它在导入之前删除模块。它需要检查 4 个模块。
代码检查文件的修改日期是否在一个范围内,如果日期较大,则导入。代码运行时会报错。
For Each objFile In objFSO.GetFolder(szImportPath).Files
If (objFSO.GetExtensionName(objFile.Name) = "bas") Or _
(objFSO.GetExtensionName(objFile.Name) = "cls") Or _
(objFSO.GetExtensionName(objFile.Name) = "frm") And _
objFile.DateLastModified > Range("ImportDate") Then
'Delete all modules/Userforms from the ActiveWorkbook
'Call DeleteVBAModulesF
szFileName = objFile.Name
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents(szFileName)
VBProj.VBComponents.Remove VBComp
Range("MacroName") = objFile.Name
Range("ImportDate") = Format(Date, "dd/mm/yyyy") & " " & Format(Time, "hh.nn.ss")
'^ Keep time as without, it will import the same module throughout the day when opened.
cmpComponents.Import objFile.path
End If
Next objFile
我希望它删除当前模块然后导入。
【问题讨论】:
-
你好罗伯特,看看this post是否适合你的需要。
-
@Damian 嗨,我已经解决了,代码如下。谢谢