Solved

system.diagnostics.process will not open MS Office documents without application open first

Posted on 2014-09-11
6
700 Views
Last Modified: 2014-09-27
I have an application with a VB6 user interface which calls a VB.NET (VS2010) DLL to generate report files in spreadsheet (.xlsx) and word processor (.docx) formats.  I use DevExpress to generate the report files then have a generic method to call system.diagnostics.process.start on the file to open the report file with what ever application the user has associated with that file type.

Public Shared Function OpenFileWithProcess(ByVal lsFileNameWithPath As String, Optional ByVal lPrintOption As PrintOutputOption = PrintOutputOption.Preview)

    Try
        Select Case lPrintOption
            Case PrintOutputOption.Preview
                Dim P As System.Diagnostics.Process
                P = Process.Start(lsFileNameWithPath)
                If Not P Is Nothing Then
                    Dim handle As IntPtr = P.Handle
                    SetForegroundWindow(handle)
                End If

            Case PrintOutputOption.Print
                Dim Proc As New Process
                Proc.StartInfo.FileName = lsFileNameWithPath
                Proc.StartInfo.UseShellExecute = True
                Proc.StartInfo.Verb = "Print"
                Proc.Start()
       End Select
    Catch ex As Exception
        If oSQL.Key_Developer Then
            Stop
        End If
        Throw ex
    End Try
End Function

Open in new window


On some Windows8 computers, when trying to preview the report file (open it in the associated application), I get the following error message and the report file will not open; "We're sorry, but Excel has run into an error that is preventing it from working correctly.  Excel will need to be closed as a result.  Would you like us to repair now?"  Same problem with Word.

But, if Excel is opened first and left open, then my application will open the report file without error.  I can also use windows explorer and double click to open the file outside of my application without error.  

I can also launch the same VB.NET dll via a separate VB.NET UI application and the report file will also without error.

Some additional information:
- vb.net application is compiled to .NET framework 4
- This application is deployed on a number of computers with a mixture of Windows7, 8 and 8.1 and Office 2007 - 2013.  Only a handful display this problem.
- User account control is set to lowest setting and user is an administrator
- The VB6 UI executable has been set to run in compatibility mode for Windows XP (SP3)

I'm wondering if someone can tell me or help me figure out what is going on here.  I am open to alternate solutions but do not want to hard wire to opening the files using Office DLLs.  I want the user to be able to open with what ever word processor or spreadsheet they are using.

Thank you for your time.
0
Comment
Question by:lesterbuildings
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
Word and Excel can be launched without having to go through a Process.

Simply reference them in your project, and launch them with code like the following:

            Dim wrd As New Microsoft.Office.Interop.Word.Application
            wrd.Visible = True

Replace Word by Excel for Excel.
0
 

Author Comment

by:lesterbuildings
Comment Utility
Thank you for the suggestion but I am strongly trying to avoid using the Microsoft Office Interops.  We do not mandate the version of Office our users have  and we have run into problems with that approach on users that have Office365 and click-to-run versions.

Seems much simpler to produce the report file and let the process take care of starting the application.
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
There is a way to circumvent your problem with different versions of Office, by using late binding instead of early binding. You lose the checkups performed by the compiler, but since all you do is launch the program, that should not be a problem.

Put the code in a module in which you have set Option Strict to Off, and code as following:

            Dim app As Object
            app = CreateObject("Word.Application")
            app.visible = True

Word is then launched from its entry in the Registry, so it will start not matter which version is installed on the computer.
0
 

Accepted Solution

by:
lesterbuildings earned 0 total points
Comment Utility
Found the solution to be unchecking the Windows XP compatibility mode on the VB6 EXE. Doing that allows Word and Excel to launch the report files without error.  Thank you to all for the suggestions.
0
 

Author Closing Comment

by:lesterbuildings
Comment Utility
The solution was suggested by another expert on a different developer help site.  Wanted to share the solution here.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The goal of this Micro Tutorial is to help navigate beginning users with the app store on Windows 8. It will explain exciting features how to maximize your PC through these apps. This will be demonstrated using Windows 8 operating system.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now