Why is VBA saying that it has found an 'ambiguous name'?
excel, vba
Solution
From MSDN :
- More than one object in the same scope may have elements with the same name.
Module-level identifiers and project-level identifiers (module names and referenced project names) may be reused in a procedure, although it makes programs harder to maintain and debug. However, if you want to refer to both items in the same procedure, the item having wider scope must be qualified. For example, if MyID is declared at the module level of MyModule , and then a procedure-levelvariable is declared with the same name in the module, references to the module-level variable must be appropriately qualified:
Dim MyID As String
Sub MySub
MyModule.MyID = "This is module-level variable"
Dim MyID As String
MyID = "This is the procedure-level variable"
Debug.Print MyID
Debug.Print MyModule.MyID
End Sub
- An identifier declared at module-level conflicts with a procedure name.
For example, this error occurs if the variable MyID is declared at module level, and then a procedure is defined with the same name:
Public MyID
Sub MyID
. . .
End Sub
Problem
When compiling some code (declarations shown below) I get the error message 'Compile Error: Ambiguous name detected. SixTables'. I have looked here and elsewhere but cannot find anything that matches my problem. What appear to be the most common causes of this error, declaring two variables with identical names or giving the same name to a function and the sub that it is called from, do not apply. And yes, I know I could just change the name to something the system was happy with, but (1) I wouldn't learn what I'm doing wrong, and (2) I chose that name for a reason - it fits its purpose exactly :-) ``` Option Explicit Dim ArmOfService As Byte Dim CharacterNumber As Long Dim CurrentTerm As Byte Dim DecorationRollMade As Byte Dim DecorationRollNeeded As Byte Dim DiceSize As Byte Dim GenAssignment Dim GenAssignmentSwitchInt As Byte Dim GenAssignmentSwitchOff As Byte Dim iLoopControl Dim jLoopControl Dim kLoopControl Dim LineIncrement As Integer Dim lLoopControl Dim Merc(100) Dim NoOfDice As Byte Dim OfficerPromotion(63 To 78) As Byte Dim PromotionRollMade As Byte Dim PromotionRollNeeded As Byte Dim Roll As Byte Dim SkillColumn Dim SixTables Dim SpecAssignmentSwitchEnd As Byte Dim SurvivalRollMade As Byte Dim SurvivalRollNeeded As Byte Dim TechLevel As Byte Dim Temp As Integer Dim Term As Byte Dim TestCount Dim UnitAssignment Dim WhichTable Dim Year As Byte ``` EDIT: I'm so embarrassed that I can hardly bring myself to explain what the problem was. I knew I hadn't duplicated a name, since I was only using it once - as a function! Thanks all for your help, I'm now going to go and hide my face in shame...