导入和导出用户窗体和模块

帮帮我! 我找不到任何地方…我已经find了很多的.frx文件的解释,但这不是问题。 我已经导出了2个模块“.bas”和一个用户表单“.frm”,它们也创build了“.frx”二进制文件。 现在的问题是,现在当我用下面的代码将它们导入到一个新的工作簿中时,在初始化用户窗体时,应用程序打开并尝试在原始工作簿中运行,在该工作簿中我编写了模块并devise了自定义用户窗体。 为什么发生这种情况,是否有办法让它加载窗体和​​模块导入到工作簿中的用户窗体?

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 

Interesting Posts