locked
AutoCorrect Macro RRS feed

  • Question

  • AutoCorrect Macro

    What code should be added to the below macro so that it also backs up formatted AutoCorrect entries. I have seen a utility that backs up formatted entries too, but it is unable to back up large autocorrect file, which this macro can do.  So, I need a macro that can back up large autocorrect file with formatted entries. I know normal.dot saves the formatted autocorrect entries, but I want this macro to do this. I also would like to know about the code to be added, which will save the backup document in correct format (Three Column Table) to restore it without making any changes because this macro uses tabs as a separator not the table.

     

    Sub autoCorrectBackup()
       'Copyright (c) 2011, Richard V. Michaels. All rights reserved.
       'You have the right to use it ... please just don't claim that you wrote it!
      
        On Error GoTo ErrMsg

        Dim doc As Word.Document
        Dim rng As Word.Range
        Dim acEnt As Word.AutoCorrectEntry
        Dim acEntries As Word.AutoCorrectEntries
        Dim mName As String: mName = "Autocorrect Backup"

        Word.Documents.Add

        With Dialogs.Item(wdDialogFileSaveAs)
            .Name = Word.Options.DefaultFilePath(wdDocumentsPath) & ":Autocorrect_Backup_" & Date$
            If .Show <> -1 Then
                MsgBox "User Aborted Save, Exiting Backup", vbExclamation, mName
                Exit Sub
            End If
            .Execute
        End With

        Set doc = Word.ActiveDocument
        Set rng = Word.Selection.Range
        Set acEntries = Word.AutoCorrect.Entries

        For Each acEnt In acEntries
            rng.Text = acEnt.Name & vbTab & acEnt.value & vbCr
            rng.Collapse Word.WdCollapseDirection.wdCollapseEnd
        Next acEnt
       
        Set rng = doc.Content
        rng.ConvertToTable Separator:=Word.wdSeparateByTabs

        doc.Variables.Add Name:="ACbackup", value:="1"

        doc.Save

        MsgBox "Autocorrect Entry Backup Complete", vbOKOnly, mName
        Exit Sub

    ErrMsg:
        MsgBox "Error: " & Err.Description, vbCritical, mName
       
    End Sub



    • Moved by Mark Liu-lxf Monday, July 9, 2012 8:39 AM (From:Visual Basic Language)
    • Edited by DS001MS Wednesday, July 25, 2012 3:09 PM
    Sunday, July 8, 2012 7:54 AM

Answers

  • Formatted AutoCorrect entries are saved in the Normal template, so that's the file you need to back up.

    Stefan Blom, Microsoft Word MVP
    Monday, July 9, 2012 8:47 AM

All replies

  • This forum is about the .Net based standalone versions of Visual Basic. Have a look at this forum instead:
    http://social.msdn.microsoft.com/Forums/en-US/worddev/threads

    Armin

    Sunday, July 8, 2012 11:15 AM
  • Formatted AutoCorrect entries are saved in the Normal template, so that's the file you need to back up.

    Stefan Blom, Microsoft Word MVP
    Monday, July 9, 2012 8:47 AM
  • AutoCorrect Macro

    What code should be added to the below macro so that it also backs up formatted AutoCorrect entries. I have seen a utility that backs up formatted entries too, but it is unable to back up large autocorrect file, which this macro can do.  So, I need a macro that can back up large autocorrect file with formatted entries.

     

    Sub autoCorrectBackup()
       'Copyright (c) 2011, Richard V. Michaels. All rights reserved.
       'You have the right to use it ... please just don't claim that you wrote it!
      
        On Error GoTo ErrMsg

        Dim doc As Word.Document
        Dim rng As Word.Range
        Dim acEnt As Word.AutoCorrectEntry
        Dim acEntries As Word.AutoCorrectEntries
        Dim mName As String: mName = "Autocorrect Backup"

        Word.Documents.Add

        With Dialogs.Item(wdDialogFileSaveAs)
            .Name = Word.Options.DefaultFilePath(wdDocumentsPath) & ":Autocorrect_Backup_" & Date$
            If .Show <> -1 Then
                MsgBox "User Aborted Save, Exiting Backup", vbExclamation, mName
                Exit Sub
            End If
            .Execute
        End With

        Set doc = Word.ActiveDocument
        Set rng = Word.Selection.Range
        Set acEntries = Word.AutoCorrect.Entries

        For Each acEnt In acEntries
            rng.Text = acEnt.Name & vbTab & acEnt.value & vbCr
            rng.Collapse Word.WdCollapseDirection.wdCollapseEnd
        Next acEnt
       
        Set rng = doc.Content
        rng.ConvertToTable Separator:=Word.wdSeparateByTabs

        doc.Variables.Add Name:="ACbackup", value:="1"

        doc.Save

        MsgBox "Autocorrect Entry Backup Complete", vbOKOnly, mName
        Exit Sub

    ErrMsg:
        MsgBox "Error: " & Err.Description, vbCritical, mName
       
    End Sub

    Monday, July 9, 2012 10:04 AM
  • That code does not back up the AC entries (no matter that the messagebox says it happens).  It makes a file of the NAME of the AC, and the text of the AC content.  The AC entries themselves are NOT backed up.  It is just text - the name and value of the AC entries.

    To back up the entries, as Stefan mentions, you need to backup Normal.  The AC entries are there.


    Word MVP


    • Edited by fumei2 Thursday, July 12, 2012 5:07 AM
    Thursday, July 12, 2012 5:06 AM