• Compile this

    Author
    Topic
    #354071

    Would someone take a minute and compile this simple VBE code and tell me what you get. I get type mismatch error (Word 97) unless I declare vbComp as Object. You’ll need a reference to VBA extensions.

    Dim vbComp As VBIDE.VBComponent
    Dim vbComps As VBIDE.VBComponents

    ‘Either of these lines cause the error
    Set vbComps = ThisDocument.VBProject.VBComponents
    or
    Set vbComps = Application.VBE.ActiveVBProject.VBComponents

    I’m trying to loop thru all the components in a project like this:

    for each vbComp in vbComps
    debug.print vbComp.Name
    ‘bla bla bla
    next

    Yes, I can do it with Object declarations, but I really want to know why I get the error.

    Viewing 1 reply thread
    Author
    Replies
    • #519421

      I don’t find a data type of VBIDE.VBComponents. VBComponents is a collection. I think you need:

      Dim vbComps As Collection
      
      • #519424

        Do you have a reference to the VBA Extensions library?

        Yes, VBComponents is a collection, a collection of VBE components, so it should work.

        Nevertheless, I tested your suggestion and get the same error.

    • #519443

      Kevin,

      This works for me:

      Dim vbComps As VBComponents
      Dim vbComp As VBComponent

      Set vbComps = ActiveDocument.AttachedTemplate.VBProject.VBComponents
      For Each vbComp In vbComps
      Debug.Print vbComp.Name
      Next

      • #519445

        That’s what I was afraid of. It should work for me too. I found identical code from an Excel programmer and pasted it into and Excel mod. Same error.

        Something fishy going on here…

        Thanks for testing for me.

      • #519454

        Geoff,

        Do me a favor, please, and tell me the name and location of the VBA Extensibility library for Office 97 (vba5). I think my problem is related to the fact that I have some Office 2000 components installed (namely Outlook 2000) and Word wants to use the library for VBA6. The library I reference is

        c:program filescommon filesmicrosoft sharedvbavba6VBE6EXT.OLB

        My guess is that is NOT the same library for VBA5. Thanks.

        • #519458

          Either Geoff’s invisible or he’s gone home.

          try this – i think it’s right…

          c:program filescommon filesmicrosoft sharedvbaVBEEXT1.OLB

          Brooke

          • #519467

            Brooke,

            While you were posting, I was hunting and testing. You are correct, that is the VB5 VBA Extensibility Library. And when I manually put that back on the reference list and retried my code — it Worked!

            What a goose chase. That means the VB6 library installed OVER the vb5 library when I installed Outlook 2000. Watch out y’all.

      • #519468

        Geoff,

        See Brooke’s post and mine after.

        • #519470

          Kevin,

          I can only duck in now and then.

          My library is different- I’ve got Microsoft Visual StudioVB98VB6ext.olb which has a time/date stamp of 18/6/98. I assume it came from VB6.

          • #519471

            Thanks though. It looks like that library has any number of incarnations. Are you deving in Office 2000 or 97?

            • #519475

              Kevin,

              OK, I’ve Office 2000. But the same code, with the same reference set, also works in Word 97.

              And that was Visual Basic 6 extensibility, not VBA extensibility. Sorry, I’ve rechecked and I was wrong before. Sorry to mislead you- the one that worked for me was the same as Brooke’s.

            • #519477

              Geoff,

              Ok, thanks. I’m all squared away now.

    Viewing 1 reply thread
    Reply To: Compile this

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: