Option Strict On
Imports Microsoft.Office.Interop.Word
Public Class Form1
Private wrdApp As Microsoft.Office.Interop.Word.Application
Private wrdDoc As Microsoft.Office.Interop.Word.Document
Private Sub closeButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles closeButton.Click
Try
wrdDoc.Close()
wrdApp.Quit()
wrdDoc = Nothing
wrdApp = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub openBlankButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles openBlankButton.Click
Try
wrdApp = New Microsoft.Office.Interop.Word.Application
wrdDoc = wrdApp.Documents.Add()
''These are optional
With wrdApp
.Visible = True
.DisplayAlerts = WdAlertLevel.wdAlertsNone
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub openExistingButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles openExistingButton.Click
Dim documentPath As Object = "Path To Existing Word Document"
Try
wrdApp = New Microsoft.Office.Interop.Word.Application
wrdDoc = wrdApp.Documents.Open(documentPath)
'These are optional
With wrdApp
.Visible = True
.DisplayAlerts = WdAlertLevel.wdAlertsNone
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class