帮助!我在任何地方都找不到这个...我找到了很多 .frx 文件的解释,但这不是问题所在。我导出了 2 个模块“.bas”和一个用户表单“.frm”,它还创建了“.frx”二进制文件。问题是,现在当我使用下面的代码将它们导入新工作簿时,在初始化用户表单时,应用程序打开并尝试在原始工作簿中运行,我在其中编写模块并设计了自定义用户表单。为什么会发生这种情况,有没有办法让它在导入表单和模块的工作簿中加载用户表单?
Sub Import_VBA(WBName)
Dim VBc As Variant
Dim exportFolder As String, VBcExt As String, testFile As String
Dim newWB As Workbook
testFile = WBName
exportFolder = "y:\ECI\Database\Outputs\InterfaceApp"
Set newWB = Workbooks(testFile & ".xlsm")
''''' Test VBA protection
On Error Resume Next
If newWB.VBProject.Protection <> 0 Then
If Err.Number = 1004 Then
Err.Clear
MsgBox "VBA Project Object Model is protected in " & newWB.Name & vbCrLf _
& vbCrLf & "Please remove VBA protection in Trust Center to continue.", _
vbExclamation + vbOKOnly, "Error"
Set newWB = Nothing
Exit Sub
Else
MsgBox Err.Number & ": " & Err.Description, vbExclamation, "Error"
Set newWB = Nothing
Err.Clear
Exit Sub
End If
End If
''''' Add Interface App Components
For Each VBc In CreateObject("Scripting.FileSystemObject").GetFolder(exportFolder).Files
Select Case LCase(Right(VBc.Name, 4))
Case ".bas", ".frm", ".cls", ".frx"
newWB.VBProject.VBComponents.Import exportFolder & "\" & VBc.Name
End Select
Next VBc
End Sub