导入错误7874后尝试重命名模块找不到module1对象

问题描述 投票:0回答:1

我试图从另一个数据库导入导出的对象。文件扩展名为vba。我创建了一个循环来遍历所有对象。我的循环确实正确地遍历了所有文件。循环确实将模块作为模块1导入第一个文件。我想将模块从模块1重命名为以前的模块名称。

我正在使用MS Access office 365。

Sub LoopThroughFiles2()
    Dim strFile As String
    Dim strNewFile As String
    Dim strPath As String
    Dim strNewPath As String
    Dim strDBName As String
    Dim strModName As String

    strDBName = Application.CurrentProject.Name
    strPath = ("C:\Users\Parents\Google Drive\Access Files\File7\")
    strFile = Dir(strPath & "*")
    Do While Len(strFile) > 0
        Debug.Print strFile
        Debug.Print strPath

        strNewFile = Replace(strFile, ".vba", ".txt", 1, , vbTextCompare)
        Debug.Print strNewFile

        Name strPath & strFile As strPath & strNewFile
        strNewPath = strPath & strFile
        strModName = Replace(strNewFile, ".txt", "")
        Debug.Print strModName
        VBE.ActiveVBProject.VBComponents.Import strNewPath
        VBProj.VBComponents("Module 1").Name = strModName 'error 424 
        DoCmd.Rename strModName, acModule, "Module1" 'error 7874

    Loop
End Sub
vba ms-access access-vba
1个回答
0
投票

您无法直接更改名称,但您可以更改属性,如下所示:

VBE.ActiveVBProject.VBComponents("Module 1").Properties("Name").Value = strModName
© www.soinside.com 2019 - 2024. All rights reserved.