Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AutoCorrect Macro (Word 97/SR2)

    I am creating a document for someone who needs to learn English. I would like to create the document as in the example below:

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: AutoCorrect Macro (Word 97/SR2)

    Here's a sample:
    <pre>Sub AddATEntries()
    'Turn selection into insertion point if not already
    If Selection.Type <> wdSelectionIP Then
    Selection.Collapse Direction:=wdCollapseStart
    End If
    'Make sure insertion point is in a logical location
    If Not Selection.Information(wdWithInTable) Then
    MsgBox "Put your cursor in the table and try again"
    Exit Sub
    End If
    'Make sure text in the first cell in the row is selected
    With Selection
    .Rows(1).Range.Columns(1).Select
    .MoveRight Unit:=wdCell
    .MoveLeft Unit:=wdCell
    End With
    'Confirm user wants to proceed
    If MsgBox("Do you want to add this row (and all subsequent rows) as " & _
    "AutoText entries?", vbQuestion + vbYesNo) = vbNo Then Exit Sub
    'Set up two variables
    Dim strATname As String, strATtext As String
    'Start looping
    With Selection
    Do
    'Store code and go to next cell
    strATname = .Text
    .MoveRight Unit:=wdCell
    'Store replacement text and go to next cell
    strATtext = .Text
    .MoveRight Unit:=wdCell
    'Add the AutoCorrect entry
    AutoCorrect.Entries.Add Name:=strATname, Value:=strATtext
    'Stop when the cell is blank (Selection.Text contains
    ' a particular end-of-cell code sequence)
    Loop Until .Text = Chr(13) & Chr(7)
    End With
    MsgBox "Done!"
    End Sub</pre>

    This macro relies on the behavior of the tab key in a table to select the text in the next cell. This saves some processing to extract the textual portion of a cell but also creates the problem that after tabbing through the last row, a new row will be added with blank cells, and in a blank cell, Selection.Text picks up the end of cell marker. I use that behavior to signal the end of the loop. Hope this helps.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoCorrect Macro (Word 97/SR2)

    Thank you so much for your reply. I will definitely try it and see what happens. Once again, thank you so very much.

    Vitoria

  4. #4
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoCorrect Macro (Word 97/SR2)

    I am sorry for not posting sooner but I have been a little under the weather. It worked beautifully. Thank you for such a prompt response.

    Vitoria

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •