' Open the Word document, go to TheBookmark,
' type some text, and display the document,
' leaving the Word server running.
Private Sub cmdOpen_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdOpen.Click
Dim file_name As String
Dim file_path As String
Dim file_title As String
Dim word_server As Word.Application
Cursor = System.Windows.Forms.Cursors.WaitCursor
cmdOpen.Enabled = False
Application.DoEvents()
file_name = txtFileName.Text
file_title = _
file_name.Substring(file_name.LastIndexOf("\") + 1)
file_path = file_name.Substring(0, _
file_name.LastIndexOf("\"))
word_server = New Word.Application()
word_server.ChangeFileOpenDirectory(file_path)
word_server.Documents.Open( _
FileName:=file_title, _
ConfirmConversions:=False, _
ReadOnly:=False, _
AddToRecentFiles:=False, _
PasswordDocument:="", _
PasswordTemplate:="", _
Revert:=False, _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Format:=Word.WdOpenFormat.wdOpenFormatAuto)
word_server.Selection.GoTo( _
What:=Word.WdGoToItem.wdGoToBookmark, _
Name:="TheBookmark")
word_server.Selection.TypeText( _
Text:="<Here is the bookmark>")
word_server.Visible = True
Cursor = System.Windows.Forms.Cursors.Default
cmdOpen.Enabled = True
End Sub
|