Skip to content

Commit 4f79934

Browse files
authored
Conditionally qualify MSForms type library
1 parent 6a3a78d commit 4f79934

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Rubberduck.Parsing/Symbols/DeclarationSymbolsListener.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,21 @@ private void DeclareControlsAsMembers(IVBComponent form)
134134
{
135135
if (form.Controls == null) { return; }
136136

137+
var libraryQualifier = string.Empty;
138+
if (form.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+
137149
foreach (var control in form.Controls)
138150
{
139-
var typeName = $"MSForms.{control.TypeName()}";
151+
var typeName = $"{libraryQualifier}{control.TypeName()}";
140152
// The as type declaration should be TextBox, CheckBox, etc. depending on the type.
141153
var declaration = new Declaration(
142154
_qualifiedModuleName.QualifyMemberName(control.Name),

0 commit comments

Comments
 (0)