EmersonH.Com

Transforming Knowledge into Power

  • Increase font size
  • Default font size
  • Decrease font size
Home VB.Net 2008 Word Automating Microsoft Word

Automating Microsoft Word

E-mail Print

Imports Microsoft.Office.Interop.Word
Module Module1
Sub Main()
Dim word As New Application
word.Visible = True
Dim doc As Document = word.Documents.Add()
Dim range As Range = doc.Range
' Insert some text
range.InsertAfter("Range1" + vbCrLf)
' Insert a bookmark, make sure the range is 0 characters long so we can insert text
range.Collapse(WdCollapseDirection.wdCollapseEnd)
doc.Bookmarks.Add("MijnBookmark", range)
' Add some more text
range.InsertAfter("Range2" + vbCrLf)
' Get a reference to the bookmark
Dim bookmark As Bookmark = doc.Bookmarks(1)
range = bookmark.Range
' Insert the text
range.Text = "Bookmark" + vbCrLf
' Change the font for the bookmark
range.Font.Color = WdColor.wdColorRed
range.Font.Italic = 1
End Sub
End Module

Last Updated on Monday, 21 December 2009 17:44