none
vb.net code to delete Word AutoCorrect entries RRS feed

  • Question

  • I currently have working VBA code on Word startup to delete certain Word AutoCorrrect entries. The code is stored in a Word global template and runs on Word startup.

                                '' setup Word environment as no GPOs exist
                                '' remove AutoCorrect entries
                                '' Dont require a Word doc open to check/set AutoCorrect entries
                                Dim acEntry As AutoCorrectEntry
                                Dim intResponse As Integer
                                Dim ArrCount As Long
                                Dim thisEntry As String
                                Dim strEntry(3) As String
                                strEntry(0) = "acn"
                                strEntry(1) = "(c)"
                                strEntry(2) = "(e)"
                                strEntry(3) = "(r)"
    
                                For ArrCount = 0 To 3
                                    thisEntry = strEntry(ArrCount)
                                    For Each acEntry In AutoCorrect.Entries
                                        If LCase(acEntry.name) = LCase(thisEntry) Then
                                            acEntry.Delete()
                                            Exit For
                                        End If
                                    Next acEntry
                                Next ArrCount

    I need to move the code from the Word startup template into the Word COM Add-ins solution.

    I found this article  

    https://channel9.msdn.com/coding4fun/articles/When-AutoCorrect-Goes-Bad


    I was wondering if anyone has sample vb.net code to delete Word AutoCorrect entries

    TIA


    • Edited by dd_ Friday, October 13, 2017 12:31 AM
    Friday, October 13, 2017 12:30 AM

All replies

  • Hi dd_,

    Since this forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tools (Not for VB6 questions). And your issue is more related to VBA. This link about vba, please refer that:

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=isvvba

    Thank you for participating in the forum activities.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 13, 2017 5:52 AM
    Moderator
  • hi Cherry

     

    In my post I have existing working code in VBA.

    I need to the VBA code converted to VB.net. Im using VS2013 VB.net

    Therefore is this the correct forum or not?

    Thanks again





    • Edited by dd_ Sunday, October 15, 2017 10:31 PM
    Sunday, October 15, 2017 10:31 PM
  •  You can use the Word Interop in vb.net to add or remove any of the AutoCorrect entries like this....

    Imports Microsoft.Office.Interop
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim WordApp As New Word.Application
            Dim WordDoc As Word.Document = WordApp.Documents.Add()
    
            'WordApp.AutoCorrect.Entries.Add("doit", "do it") 'This will add an auto correct entry that changes "doit" to "do it"
    
            WordApp.AutoCorrect.Entries.Item("doit").Delete() 'This will delete the "doit" to "do it" auto correct entry
    
            WordApp.Visible = True
    
        End Sub
    
    End Class


    If you say it can`t be done then i`ll try it

    Sunday, October 15, 2017 11:58 PM
  •  If you do not want to actually open a document that you are automating but,  just want to add or remove autocomplete entries,  you can try it like this.  It seems to work on my end without the user being able to see anything.

    Imports Microsoft.Office.Interop
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim WordApp As New Word.Application
            Dim WordDoc As Word.Document = WordApp.Documents.Add()
            WordApp.Visible = False
    
            WordApp.AutoCorrect.Entries.Add("doit", "do it") 'This will add an auto correct entry that changes "doit" to "do it"
    
            'WordApp.AutoCorrect.Entries.Item("doit").Delete() 'This will delete the "doit" to "do it" auto correct entry
    
            WordApp.Quit()
            System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp)
            WordApp = Nothing
        End Sub
    
    End Class
    


    If you say it can`t be done then i`ll try it

    Monday, October 16, 2017 12:27 AM
  • Hi dd_,

    It seems that IronRazerz  solved your issue now, please remember to close your thread by marking his post an answer. It is beneficial to other community members who face the same issue.

    Thanks for your understanding.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 24, 2017 5:57 AM
    Moderator