bogorman
asked on
Com Exception was unhandled error using VS2005
Am a complete newcomer to VS2005. I have a reasonable knowledge of Access Visual Basic.
Am trying to develop a very simple Windows application for use on local machines (not on the server).
I have a simple form with the following coding:
Imports System.IO
Imports Microsoft.Office.Interop.W ord
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "Printing Letters to Schools"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create new document based on template
Dim strTemplateFile As System.String = "C:\Web Design\LIFEnet\LifeMergeTe mplate.dot "
Dim WordtemplateFile As New _
System.IO.FileInfo(strTemp lateFile)
' See if the file specified exists
If (WordtemplateFile.Exists) Then
Dim wordApplication As New Microsoft.Office.Interop.W ord.Applic ation
' For improved performance and to prevent screen flashing set visibility to false
wordApplication.Visible = False
' Add the template to the new word application
Dim wordTemplate As Microsoft.Office.Interop.W ord.Docume nt = wordApplication.Documents. Add( _
CType(strTemplateFile, Object), , , False)
wordApplication.Visible = True
' Activate the new wordTemplate document
wordTemplate.Activate()
End If
End Sub
End Class
The problem is when I run the application with Debug.Start Debugging and click on the button I get a "Com Exception was unhandled" error (80040154) on the line:
Dim wordApplication As New Microsoft.Office.Interop.W ord.Applic ation
Have added a reference to the Microsoft Word 11.0 Object Library and there is one to Microsoft Office 11.0 Object Library.
Can anyone tell me what is wrong? There are no errors shown on the Error List.
Am trying to develop a very simple Windows application for use on local machines (not on the server).
I have a simple form with the following coding:
Imports System.IO
Imports Microsoft.Office.Interop.W
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "Printing Letters to Schools"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create new document based on template
Dim strTemplateFile As System.String = "C:\Web Design\LIFEnet\LifeMergeTe
Dim WordtemplateFile As New _
System.IO.FileInfo(strTemp
' See if the file specified exists
If (WordtemplateFile.Exists) Then
Dim wordApplication As New Microsoft.Office.Interop.W
' For improved performance and to prevent screen flashing set visibility to false
wordApplication.Visible = False
' Add the template to the new word application
Dim wordTemplate As Microsoft.Office.Interop.W
CType(strTemplateFile, Object), , , False)
wordApplication.Visible = True
' Activate the new wordTemplate document
wordTemplate.Activate()
End If
End Sub
End Class
The problem is when I run the application with Debug.Start Debugging and click on the button I get a "Com Exception was unhandled" error (80040154) on the line:
Dim wordApplication As New Microsoft.Office.Interop.W
Have added a reference to the Microsoft Word 11.0 Object Library and there is one to Microsoft Office 11.0 Object Library.
Can anyone tell me what is wrong? There are no errors shown on the Error List.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Have solved my own problem!
After much work found that Office was corrupted. Reinstalled and it works!
Thanks, anyway, dstanley9 for trying to help.
Brian
Have solved my own problem!
After much work found that Office was corrupted. Reinstalled and it works!
Thanks, anyway, dstanley9 for trying to help.
Brian
ASKER
Hi dstanley9,
Sorry for delay. Even though I found the answer myself you did your best, so will assign the points.
Regards
Brian
Sorry for delay. Even though I found the answer myself you did your best, so will assign the points.
Regards
Brian
ASKER
Against the InnerException on the View Details dialog it says "Nothing".
Would be grateful for any other ideas.
Brian