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

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net Tutorial » Windows » Word 




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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.