0

Hi, can anyone help me. I've trying to display existing word document in vb.net but i keep getting this error:

D:\System-new\DLIMS\PSM2\FormUserGuideWord.vb(58): Type 'COMExceptionMessageBox.Show' is not defined.

I have add reference (Microsoft word 11.0 because im using ms word 2003) to my project but i still cannot display the word document.
Below is the code that i write to open word document in vb.net 2003:

Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.Word

Public Class FormUserGuideWord
Inherits System.Windows.Forms.Form

Private Sub FormUserGuideWord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strFileName As String
Dim word As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document
Try
doc = Word.Documents.Open("D:\System\DLIMS\UserGuide.doc")doc.Activate()
Catch ex As COMExceptionMessageBox.Show("Error accessing Word document.")
End Try

End Sub
End Class

Hopefully someone can help me to solve my problem. TQ.

4
Contributors
3
Replies
17
Views
9 Years
Discussion Span
Last Post by Reverend Jim
0

Hi PJA.

Bear with me as this is my first post on daniweb :)

Replace your code with the following and your problem should be solved.

Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.Word

Public Class FormUserGuideWord
Inherits System.Windows.Forms.Form

Private Sub FormUserGuideWord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strFileName As String
Dim word As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document
Try
doc = Word.Documents.Open("D:\System\DLIMS\UserGuide.doc")doc.Activate()
Catch ex As COMExceptionMessageBox.Show("Error accessing Word document.")
End Try

End Sub
End Class

When you attempt to Catch the COM exception you then need to show a messagebox.

Hope this was helpful

Regards
Leigh

Edited by pritaeas: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.