Results 1 to 2 of 2

Thread: Runtime error 32813 - Method 'Name' of object '_VBComponent' failed

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2013
    Posts
    14

    Runtime error 32813 - Method 'Name' of object '_VBComponent' failed

    I am trying to rename a module which leads to the run time error. In the below code, 'vbComp.name = moduleName', this line is causing the run time error. When I looked on it more, I found that the same module already exists and because of that it not allowing it to rename. Even though I called Remove reference, it is actually not removing the reference.. I tried Doevents, I called the remove reference code in a separate procedure as I shown below.. Still after executing the code, the module is not removed.

    Some additional information. So basically this code is being called in 'a.xla' and the XLAName being passed is a different xla 'b.xla'

    Code:
    Private Sub AddFileToAddIn(XLAName As String, moduleName As String, Filename As String)
        Dim vbc As VBComponent
        Dim ActiveProjName As String
        ActiveProjName = Application.VBE.ActiveVBProject.name
        Dim vbproj As VBProject
        Dim vbComp As VBComponent
        ' Find the project named XLAName
        For Each vbproj In Application.VBE.VBProjects
            If vbproj.name = XLAName Then
                ' Add the file named FileName
                Set vbComp = vbproj.VBComponents.Import(Filename)
                If Not vbComp Is Nothing Then ' If we have successfully imported the file
                    ' See if a module with the name - ModuleName - already exists in this project, and if so, delete it                    
                    RemoveModuleFromAddin vbproj, moduleName  '-----> **Not deleting the moduleName**
                    ' Change the new modules name to ModuleName from "module1"
                    vbComp.name = moduleName '---->**Since the moduleName is not deleted and it exists, renaming it is causing the run time error.**
                End If
                Exit Sub
            End If
        Next vbproj
    End Sub
    
    Private Sub RemoveModuleFromAddin(proj As VBProject, moduleName As String)
        Dim module As VBComponent
        For Each module In proj.VBComponents
            If module.name = moduleName Then
                proj.VBComponents.Remove module
                Exit Sub
            End If
        Next module
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Runtime error 32813 - Method 'Name' of object '_VBComponent' failed

    i would believe that to complete the removal of the module the code must finish or break, for testing, you could try a stop statement after the removemodulefromaddin

    one work around maybe to delete the code from the module then add the code from the imported file, but i have not tested this
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width