Avatar billede agatheb Nybegynder
26. maj 2003 - 13:25 Der er 5 kommentarer og
1 løsning

Remove a module in VBA for Excel

Hi, I'm trying to remove a module, but I keep getting errors (438)
The code I'm using is:
Workbooks(Books_to_do1)).
VBProject.VBComponents(4).Remove

But I've also tried:
Set Old_project = Workbooks(Books_to_do1)).
VBProject.VBComponents(Sheets(I).Name)
Old_project.remove

And:
For Each M In Workbooks(Books_to_do1)).
VBProject.VBComponents
    If M.Type = 1 Then
        If M.Name = Sheets(I).Name Then
            M.Remove
        End If
    End If
Next
Avatar billede martin_moth Mester
26. maj 2003 - 15:14 #1
Well, one error I just found is this:

Correct
  Workbooks(Books_to_do1)).VBProject.VBComponents(4).Remove
to
  Workbooks(Books_to_do1).VBProject.VBComponents(4).Remove

If this is not the answar you need, please type the errormessage (if any), not just the #
Avatar billede martin_moth Mester
26. maj 2003 - 15:17 #2
And in general correct

  ))
to
  )
That is, the number of ( should match the number of )

And you cannot break your code up as you seem to do:
  For Each M In Workbooks(Books_to_do1)).
  VBProject.VBComponents

It MUST be in one line

  For Each M In Workbooks(Books_to_do1).VBProject.VBComponents
Avatar billede agatheb Nybegynder
26. maj 2003 - 15:30 #3
Hej Martin,

Sorry, the missing ) was an error of mine. But was correct in the code. I didn't get any errors when compiling it. I found out what was wrong, or actually got some help from someone else.
I didn't refer to an object to remove.
The correct code is:

    Set Old_project = Workbooks(Books_to_do(1)).VBProject.VBComponents(Sheets(I).Name)
   
    Workbooks(Books_to_do(1)).VBProject.VBComponents.Remove Old_project

Thanks for your time anyway.
Agathe
Avatar billede agatheb Nybegynder
26. maj 2003 - 15:33 #4
How do I close this question by the way? (No need to mention I'm new at this..... ;-))
Avatar billede martin_moth Mester
26. maj 2003 - 16:10 #5
I ditn't offer any help, so place an answar of your own, and when your own answar appears, accept it, thereby givint all the points back to your self. An accepted question is a closed question. Best regards
Avatar billede agatheb Nybegynder
26. maj 2003 - 16:12 #6
Thanks
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester