Samples

Spell Check Text Elements in ArcMap

Description:

This sample shows how to automate Microsoft Word to do spell checking for ArcMap.
Products:

ArcView: VBA

Platforms: Windows

Requires: Microsoft Word object library

Minimum ArcGIS Release: 9.0

How to use:
  1. Add some text to an ArcMap document.
  2. Copy and paste the code into the ArcMap VBA Editor.
  3. Add reference of Microsoft Word Object Library through VBA Editor menu: Tools->References....
  4. Switch to ArcMap and select the text element to check. Run the SpellCheck macro. The text element will be examined by Microsoft Word's spellchecker. If the spelling or grammar has an error, a dialog box will prompt for changes.
          Public Sub SpellCheck()
  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
  'Hard coded, check the first selected element
  Set pTE = pGC.SelectedElement(0)
  
  Dim sz As String
  sz = pTE.Text
  Dim wdApp As Word.Application
  Dim wdDoc As Document

  Set wdApp = New Word.Application
  Set wdDoc = wdApp.Documents.Add
  wdApp.Selection.Text = sz
  wdApp.Dialogs(wdDialogToolsSpellingAndGrammar).Show
  ' if the Cancel button is clicked, there will be one character
  If Len(wdApp.Selection.Text) > 1 Then
     pTE.Text = wdApp.Selection.Text
  Else
     wdApp.Quit
     Set wdApp = Nothing
     Exit Sub
  End If
  wdDoc.Close wdDoNotSaveChanges
  wdApp.Quit
  Set wdApp = Nothing
  pDoc.ActiveView.Refresh
End Sub

        

Feedback Send feedback on this sample