Solved

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

Posted on 2014-09-11
6
731 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
ID: 40325293
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
ID: 40326272
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
ID: 40326323
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
ID: 40336509
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
ID: 40347382
The solution was suggested by another expert on a different developer help site.  Wanted to share the solution here.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

829 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