@@ -133,11 +133,22 @@ private IEnumerable<IAnnotation> FindAnnotations(int line)
133
133
private void DeclareControlsAsMembers ( IVBComponent form )
134
134
{
135
135
if ( form . Controls == null ) { return ; }
136
- var msFormsLib = _state . DeclarationFinder . FindProject ( "MSForms" ) ;
137
136
137
+ var libraryQualifier = string . Empty ;
138
+ if ( _qualifiedModuleName . ComponentType == ComponentType . UserForm )
139
+ {
140
+ var msFormsLib = _state . DeclarationFinder . FindProject ( "MSForms" ) ;
141
+ //Debug.Assert(msFormsLib != null);
142
+ if ( msFormsLib != null )
143
+ {
144
+ // given a UserForm component, MSForms reference is in use and cannot be removed.
145
+ libraryQualifier = "MSForms." ;
146
+ }
147
+ }
148
+
138
149
foreach ( var control in form . Controls )
139
150
{
140
- var typeName = control . TypeName ( ) ;
151
+ var typeName = $ " { libraryQualifier } { control . TypeName ( ) } " ;
141
152
// The as type declaration should be TextBox, CheckBox, etc. depending on the type.
142
153
var declaration = new Declaration (
143
154
_qualifiedModuleName . QualifyMemberName ( control . Name ) ,
@@ -155,11 +166,6 @@ private void DeclareControlsAsMembers(IVBComponent form)
155
166
null ,
156
167
true ) ;
157
168
158
- if ( msFormsLib != null )
159
- {
160
- declaration . AsTypeDeclaration = _state . DeclarationFinder . FindClassModule ( typeName , msFormsLib , true ) ;
161
- }
162
-
163
169
AddDeclaration ( declaration ) ;
164
170
}
165
171
}
0 commit comments