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

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.
lesterbuildingsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
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
lesterbuildingsAuthor Commented:
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
Jacques Bourgeois (James Burger)PresidentCommented:
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
lesterbuildingsAuthor Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lesterbuildingsAuthor Commented:
The solution was suggested by another expert on a different developer help site.  Wanted to share the solution here.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 8

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.