Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspection for document/sheet-hosted ActiveX controls having shape names that shadow sheet member names #2755

Open
ThunderFrame opened this issue Feb 28, 2017 · 3 comments

Comments

@ThunderFrame
Copy link
Member

It's possible to add an ActiveX control to a sheet, and name the hosting Shape as Name which shadows/conflicts with the Name property of a Worksheet class. That makes for a disconnect between the shape name and the name of the WithEvents object that sources events in the sheet's code-behind.

RD should have an inspection that looks for such naming conflicts.

The VBA to get the real control name requires explicitly casting the OLEObject.Object to the underlying type:

  Dim oleobj As OLEObject
  Set oleobj = Sheet1.OLEObjects("Name")

  Debug.Print TypeName(oleobj.Object) 'Prints "CommandButton"
  Debug.Print oleobj.Object.Name 'Runtime error 438 - Object doesn't support this property or method

  Dim cb As CommandButton
  Set cb = oleobj.Object
  Debug.Print cb.Name 'Prints "NameFoo"

ref: #389

@bclothier
Copy link
Contributor

Note that the similar problem exist in Access, where by default adding a control to form is given the same name as the backing field. This has the effect of shadowing the Access.AccessField with the Access.Control; an inspection should recommend renaming control so they are distinct. If there are other cases like that, it might be more desirable to make this inspection more generic and extensible so that it can be easily set up to check for different collections that may contain the conflicting names.

@retailcoder
Copy link
Member

Wouldn't the upcoming ShadowedDeclarationInspection would/should take care of this... if we picked up document-embedded OLEObject controls? If every Worksheet module had a "hidden" Control declaration for every embedded OLEObject control on the sheet, then a name clash would be picked up automagically already, wouldn't it?

@Vogel612
Copy link
Member

Sooo... is this fixed by ShadowedDeclarationInspection or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants