Edit Word document : Word « Windows « VB.Net Tutorial





public class Test
   public Shared Sub Main
        Dim objWordApp As Word.Application
        objWordApp = New Word.Application

        Dim objWordApp As Word.Application
        objWordApp = New Word.Application

        Dim objDoc As Word.Document

        'Show the Word application window if checked.
        objWordApp.Visible = IIf(chkShowWord.Checked, True, False)

        'Open an existing document.
        objWordApp.Documents.Open("C:\Temp\Sample.doc")
        objDoc = objWordApp.ActiveDocument

        'Find and replace some text.
        objDoc.Content.Find.Execute(FindText:="VB", _
            ReplaceWith:="Visual Basic Express", _
            Replace:=Word.WdReplace.wdReplaceAll)
        While objDoc.Content.Find.Execute(FindText:="  ", _
            Wrap:=Word.WdFindWrap.wdFindContinue)
            objDoc.Content.Find.Execute(FindText:="  ", ReplaceWith:=" ", _
                Replace:=Word.WdReplace.wdReplaceAll, _
                Wrap:=Word.WdFindWrap.wdFindContinue)
        End While

        'Save and close the document.
        objWordApp.Documents.Item(1).Save()
        Console.WriteLine("Replaced all instances of 'VB' with 'Visual Basic Express' " & _
            "and saved the document")




        objWordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
        objWordApp.Quit()
        objWordApp = Nothing



        objWordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
        objWordApp.Quit()
        objWordApp = Nothing
   End Sub
End class










24.20.Word
24.20.1.Word Selection
24.20.2.Create Word document and print
24.20.3.Type Text
24.20.4.InsertAfter
24.20.5.Edit Word document
24.20.6.Word Spell Checker