Solved

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

Posted on 2014-09-11
6
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
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…

688 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