PDA

View Full Version : 2010 'Compile Error Ambiguous Name Detected'



Janine
11-06-2010, 03:40 AM
Hi, :hi:
Moving this macro to Word 2010 template and I am getting the below error:-

sArr = split("Clause^w") ' your list ***2010 Error: Compile Error Ambiguous Name Detected

Any ideas please - thank you.

Sub HighlightListWords1()
'Clause 10 and clauses 15 and 22, Clause 22
' ***
' I have a list of 25 words... can I click a button and have Word
' highlight wherever those words appear?
Dim sArr() As String
Dim rTmp As Range
Dim x As Long

sArr = split("Clause^w") ' your list ***2010 Error: Compile Error Ambiguous Name Detected

Options.DefaultHighlightColorIndex = wdYellow
For x = 0 To UBound(sArr)
Set rTmp = ActiveDocument.Range
With rTmp.Find
.text = sArr(x)
.Replacement.text = sArr(x)
.Replacement.Highlight = True
.Replacement.Font.Bold = True
.Replacement.text = "Clause^s"
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
With Selection
.Find.Execute findText:="assessment and plan:", Forward:=False, Wrap:=wdFindStop, MatchCase:=False
If .Find.Found Then
.InsertAfter vbCr & "1." & Chr(32) & Chr(32)
.Start = .End
.End = .Start
End If
End With
End Sub

Paul_Hossler
11-06-2010, 07:18 AM
1. Assuming that the bit after the first End Sub was too much copying


With Selection
.Find.Execute findText:="assessment and plan:", Forward:=False, Wrap:=wdFindStop, MatchCase:=False
If .Find.Found Then
.InsertAfter vbCr & "1." & Chr(32) & Chr(32)
.Start = .End
.End = .Start
End If
End With
End Sub


2. I can force the error message, but the code you have works fine in 2010 for me.


Sub HighlightListWords1()
Dim sArr() As String
Dim rTmp As Range
Dim x As Long

sArr = Split("Clause^w") ' your list ***2010 Error: Compile Error Ambiguous Name Detected

Options.DefaultHighlightColorIndex = wdYellow

For x = 0 To UBound(sArr)
Set rTmp = ActiveDocument.Range
With rTmp.Find
.Text = sArr(x)
.Replacement.Text = sArr(x)
.Replacement.Highlight = True
.Replacement.Font.Bold = True
.Replacement.Text = "Clause^s"
.Execute Replace:=wdReplaceAll
End With
Next

End Sub

'Force error message
Function Split(s As String)
MsgBox s
End Function
Function Split(s As String)
MsgBox s
End Function


So maybe Split is defined more that once? Split() only became an intrinsic VBA function in 2007 (I think) so I used to have my own.

Try doing a Find in the project and see if it's defined somewhere you don't expect it

Paul

Janine
11-06-2010, 05:46 PM
Yes too much copying!,
I'll see what it does today... It was working in 2010.

Thank you.