Solved

Com Exception was unhandled error using VS2005

Posted on 2007-03-28
5
246 Views
Last Modified: 2013-11-26
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.Word
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\LifeMergeTemplate.dot"
        Dim WordtemplateFile As New _
           System.IO.FileInfo(strTemplateFile)

        ' See if the file specified exists
        If (WordtemplateFile.Exists) Then
            Dim wordApplication As New Microsoft.Office.Interop.Word.Application

            ' 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.Word.Document = 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.Word.Application

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.
0
Comment
Question by:bogorman
  • 3
5 Comments
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 total points
ID: 18809379
Try debugging and looking at the InnerException.  It may give you more detail.
0
 

Author Comment

by:bogorman
ID: 18809492
Hi,
Against the InnerException on the View Details dialog it says "Nothing".
Would be grateful for any other ideas.
Brian
0
 

Author Comment

by:bogorman
ID: 18852394
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
0
 

Author Comment

by:bogorman
ID: 19133504
Hi dstanley9,
Sorry for delay. Even though I found the answer myself you did your best, so will assign the points.
Regards
Brian
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Batch file or script with password 22 68
Object Oriented Programming, C#, referencing, scoping. 13 69
Powershell File Sort 8 41
C# Service FileSystemwatcher isse 9 27
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question