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.

Ricardo Diaz
  • 5,658
  • 2
  • 19
  • 30
  • 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! – FreeSoftwareServers Oct 29 '19 at 05:34

1 Answers1

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

Ricardo Diaz
  • 5,658
  • 2
  • 19
  • 30
  • 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 Oct 29 '19 at 11:17
  • 2
    Note (for completeness) that selecting `Adjust attribute annotation` will _remove_ the `'@PredeclaredID` annotation from your code. – FreeMan Oct 29 '19 at 12:49