HOW TO
Instructions provided explain how to check the spelling of the selected text elements in a map document programmatically using Visual Basic for Applications (VBA) code.
Note:
The code sample requires Microsoft Word to be installed on the computer being used.
Note:
If there is already an existing UIButtonControl or the name of the UIButtonControl needs to be changed, the change needs to be made to the UIButtonControl code portion below, accordingly, before the button can be used.
Code:
Private Sub UIButtonControl1_Click()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pGC As IGraphicsContainerSelect
If pDoc.ActiveView Is pDoc.PageLayout Then
Set pGC = pDoc.PageLayout
Else
Set pGC = pDoc.FocusMap
End If
Dim pTE As ITextElement
Dim i As Integer
i = 0
Dim sz As String
Dim wdApp As Word.Application
Dim wdDoc As Document
'go through each selected element
Do Until i = pGC.ElementSelectionCount
'skip any non text elements
If Not TypeOf pGC.SelectedElement(i) Is ITextElement Then
i = i + 1
'check only text elements
Else
Set pTE = pGC.SelectedElement(i)
sz = pTE.Text
'add text to word document and open spell check
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add
wdApp.Selection.Text = sz
wdApp.Dialogs(wdDialogToolsSpellingAndGrammar).Show
' if Cancel button is clicked, there will be one character
If Len(wdApp.Selection.Text) > 1 Then
'make spelling changes to the text element
pTE.Text = wdApp.Selection.Text
Else
wdApp.Quit
Set wdApp = Nothing
Exit Sub
End If
'Close Word
wdDoc.Close wdDoNotSaveChanges
wdApp.Quit
'next text element
i = i + 1
End If
Loop
Set wdApp = Nothing
pDoc.ActiveView.Refresh
End Sub
Get help from ArcGIS experts
Download the Esri Support App