Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(48, 32)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(88, 24)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Type Text"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(240, 101)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    'Example is using reference of Microsoft Word 2000 dll library to automate and demonstrate the 
    'activites in the examples so if you find any trouble in running example then install microsoft word 2000.
    Dim WordApp As New Word.Application
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'create new word document
        Dim doc As New Word.Document
        'add new word document to word aplication documents collection and 
        'set the reference of newly created document to "doc" variable
        doc = WordApp.Documents.Add()
        'string to write 
        Dim str As String
        str = "Text Formatting:"
        'with the word app selection write the value in the document
        With WordApp.Selection
            'set the word selection font size +2 to the selection font size 
            .Font.Size = WordApp.Selection.Font.Size + 2
            'making selection font to bold
            .Font.Bold = True
            'inserting text in the document
            .TypeText(str)
            'setting font size back to current-2 
            .Font.Size = WordApp.Selection.Font.Size - 2
            'making the selected font back to false  
            .Font.Bold = False
            'start paragraph
            .TypeParagraph()
            'change the pragraph text color  to red
            .Font.Color = Word.WdColor.wdColorDarkRed
            'set the selection font not to italic
            .Font.Italic = False
            'inserting text to the document. that will apear in red  
            .TypeText("This sentence will appear in red. ")
            'start paragraph
            .TypeParagraph()
            'change the paragraph text color to black 
            .Font.Color = Word.WdColor.wdColorBlack
            'set the selection font to italic
            .Font.Italic = True
            'setting font size back to current+2 
            .Font.Size = WordApp.Selection.Font.Size + 2
            'inserting text to the document. that will apear in black  
            .TypeText("Text color was reset to black, " & _
                    "but the font size was increased by two points")
        End With
        'filename   
        Dim fName As String
        SaveFileDialog1.Filter = "Documents|*.doc"
        SaveFileDialog1.ShowDialog()
        fName = SaveFileDialog1.FileName
        'if fname is nothing then show document's save as dialog 
        If fName <> "" Then
            Try
                doc.SaveAs(fName)
            Catch exc As Exception
                MsgBox("Failed to save document" & _
                        vbCrLf & exc.Message)
            End Try
        End If
        'counting of paragraphs word and characters
        MsgBox("The document contains " & doc.Paragraphs.Count & " paragraphs " & vbCrLf & _
                doc.Words.Count & " words and " & doc.Characters.Count & " words")
        'closing document 
        doc.Close(Word.WdSaveOptions.wdDoNotSaveChanges)

    End Sub


End Class