6

As a Rubberduck and OOP newbie I'm still learning how to use the software and take advantage of the programming techniques

First time I saw about folder annotations (https://github.com/rubberduck-vba/Rubberduck/wiki/Using-@Folder-Annotations) it was quite intuitive how it worked.

But then came the VB_Attribute Annotations (https://github.com/rubberduck-vba/Rubberduck/wiki/VB_Attribute-Annotations) which I didn't quite know how to made them work.

Hope this saves some time to peolple looking to use this feature

EDIT:

To contextualize the need of Attributes, here is a great post I found by Christopher J. McClellan

https://christopherjmcclellan.wordpress.com/2015/04/21/vb-attributes-what-are-they-and-why-should-we-use-them/

And the beauty about RubberDuck is that you don't need to do the Export/Edit/Import part manually, and it does it with a couple of clicks as described in the answer bellow.

1
  • 2
    There is so much to RubberDuck I don't know or use! I installed it when I realized I wanted to get into VBA but I know I don't use it's potential, thanks for sharing! Can you add more details (perhaps to question portion) about why I would want to do this for perhaps an even more newbie to RD! Commented Oct 29, 2019 at 5:34

1 Answer 1

8

To apply a predeclared id (set it to true) follow this steps:

1- Enable the Rubberduck code explorer window

enter image description here

2- At the top of the class, add the text: '@PredeclaredID

enter image description here

Note: In the Code Explorer Window you can see when a Class has a Predeclared Attribute set to true because it has (PredeclaredId) in parenthesis next to its name

enter image description here

3- Launch Rubberduck "Code inspections"

enter image description here

4- Hit the "Refresh" button

enter image description here

5- In the "filter by descripcion" textbox type "pred"

enter image description here

6- Select the Issue and click the "fix" button

enter image description here

7- Select "Adjust attributes value"

Now the code explorer should show the "Predeclared" tag next to the class name

enter image description here

2
  • 4
    Just to note an alternate path esp. when creating new module - on the Code Explorer, you can use the menu (or right-click) to insert a new module, which one of the choice is a "template" which has one -- predeclared class. This approach avoids the need to do parsing twice when inserting a new module.
    – this
    Commented Oct 29, 2019 at 11:17
  • 2
    Note (for completeness) that selecting Adjust attribute annotation will remove the '@PredeclaredID annotation from your code.
    – FreeMan
    Commented Oct 29, 2019 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.