Results 1 to 20 of 20

Thread: [RESOLVED] VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10 Pro

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Resolved [RESOLVED] VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10 Pro

    I purchased a new computer with Windows 10 home. I installed Microsoft Office 2007 and Visual Studio 2010 Pro. Luckily I had all my apps on a USB drive so I plugged that into my new computer and all seemed to work fine. I then upgraded to Windows 10 Pro because I needed the Remote desktop feature. After doing the upgrade my application would not recognize or load Excel. I uninstalled Office 2007 and then reinstalled it but that did not help.
    Any suggestions will be greatly appreciated.

    Richard.

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    After doing the upgrade my application would not recognize or load Excel
    That's a rather vague statement. Is it throwing an error? If so, what's the error. Post the relevant code so we can see what you're trying to do.

    Have you checked your project references to make sure they are all still valid, maybe a path has changed.

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Yes I thought of that just after I made the post.

    I am going to try to attach some screen grabs that will show my code as well as the errors. What I did not grab was the Imports Microsoft.Office.Interop

    I hope this info will help.

    Thanks in advance. Richard
    Attached Images Attached Images    

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    I don't know why changing OS to Pro would make this error occur. To be honest I've never tried this method of creating a workbook.

    Try this way and see what happens,
    Code:
                Dim xlWorkBook As Excel.Workbook
                Dim xlWorkSheet As Excel.Worksheet
                Dim xlApp = New Excel.Application
    
                xlWorkBook = xlApp.Workbooks.Add
                xlWorkSheet = CType(xlWorkBook.Sheets("sheet1"), Excel.Worksheet)

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Thanks very much for the suggested code but as you can see in the attached image I get the same error. I think it must have something to do with the warnings that I attached in my previous reply but when I google those warnings all references to that issue deal with developers having multiple versions of Microsoft Office installed and I do not have multiple versions. Any suggested solutions refer to removing a registry entry but those entries are not in my registry to remove.

    Thanks again! Any other thoughts?

    Richard
    Attached Images Attached Images  

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Sorry, I don't have an answer for you. I did do a Google search on "Visual Basic QueryInterface" an found some information but most of them were using a lot newer version of Office and VS, but it's worth a look. You might try posting this problem in the Office Automation Forum on this site. Good luck

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Thanks for trying. I do appreciate it.
    I have been working with late binding excel today which creates an excel object and it seems to work fine BUT I cannot figure out how to tell when the user exits excel and therefore do not know when to kill the process. Keeps the mind active I guess!

    I will try your suggestion and see if anyone there can help.

    Richard

  8. #8
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    This example has nothing to do with late binding and I hesitate to post it because it's a hack, so take it for what it's worth, maybe nothing.

    Code:
        Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
        <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
        Public Function SetForegroundWindow(ByVal hWnd As IntPtr) As Boolean
        End Function
    
        <DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindow")> _
        Public Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
        End Function
    
        Public Function fnGetProcessHandle(ByVal sAppTitle As String) As IntPtr
            Dim Proc As Process
            For Each Proc In Process.GetProcesses
                If Proc.MainWindowTitle.ToUpper.Contains(sAppTitle) Then
                    Return FindWindow(Nothing, Proc.MainWindowTitle)
                End If
            Next
        End Function
    
                xlApp.Visible = True
                Dim hWnd = fnGetProcessHandle("MICROSOFT EXCEL")
                Dim hWndApp = GetForegroundWindow
                If Not hWnd = IntPtr.Zero Then
                    SetForegroundWindow(hWnd)
                Else
                    MessageBox.Show("window not found")
                End If
                MessageBox.Show("Closing Excel")
    
                xlApp.Quit()
                GC.Collect()
                GC.WaitForPendingFinalizers()
    
                Marshal.FinalReleaseComObject(xlWorkSheet)
                Marshal.FinalReleaseComObject(xlWorkBook)
                Marshal.FinalReleaseComObject(xlApp)
                xlApp = Nothing
    
                If Not hWndApp = IntPtr.Zero Then
                    SetForegroundWindow(hWndApp)
                End If
    What this does is display a MessageBox behind the Excel window which stop program execution. When the Excel window is closed/minimized/moved and you click OK on the MessageBox the Excel object is killed.

    There's probably a better way but this was a one time issue for me and at the time I could find a better solution.

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Thanks for that Wes4dbt I'll try it tomorrow. I'm in Ontario Canada so time to quit and go shovel snow before dinner.

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Well I tried your code but did not like the message popup because I am sure my program users would be confused to say the least! My app is on a server and many users have a copy running during the day and trying to provide support is not easy. The other issue that I found was that if I hovered the mouse over anything other than the cells, windows decided the foreground window title was changed and exited.

    Eventually I came up with a "HACK" that does what I need it to do. I have no idea how to attach the code but if you tell me how to do it I'll show you my work around..... Not very professional but it does what I need it to do.

  11. #11
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Just guessing but how are you referencing Excel? Some of our apps are using the GAC assembly and maybe you need to point it there for the new OS.
    Please remember next time...elections matter!

  12. #12

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    I have these two references in My Project
    Microsoft Excel 12.0 Object Library (Type = COM, Version = 1.6.0.0, Copy Local = False, Path = C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0_71e9bce111e9429c\Microsoft.Offi ce.Interop.Excell.dll

    Microsoft Office 12.0 Object Library (Type = COM, Version = 2.4.0.0, Copy Local = False, Path =
    C:\WINDOWS\assembly\GAC_MSIL\.Office\15.0.0.0_71e9bce111e9429c\Office.dll

    I also Import Microsoft.Office.Interop

    A typical sub to create the spread sheet is like the following:

    Private Sub SendDataToExcel()
    Dim xlApp As Excel.Application = New Microsoft.Office.Interop.Excel.Application()
    'Check to be sure Microsoft Excel is installed on this machine
    If xlApp Is Nothing Then
    MessageBox.Show("Excel is not properly installed!!")
    Exit Sub
    End If
    'Create the work book
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim misValue As Object = System.Reflection.Missing.Value


    xlWorkBook = xlApp.Workbooks.Add(misValue)
    xlWorkSheet = xlWorkBook.Sheets("sheet1")
    xlWorkSheet.Range("A:G").EntireColumn.ColumnWidth = 22
    xlWorkSheet.Range("B:B").EntireColumn.ColumnWidth = 45
    xlWorkSheet.Range("A:G").EntireColumn.HorizontalAlignment = Excel.Constants.xlLeft '.xlRight
    xlWorkSheet.Range("A:G").EntireColumn.NumberFormat = "@"


    xlWorkSheet.Cells(1, 2) = UCase(ReportName)
    xlWorkSheet.Cells(1, 4) = "REPORT DATE " & MySQL_Date_Format(DateTime.Today)


    xlWorkSheet.Cells(2, 1) = "PON"
    xlWorkSheet.Cells(2, 2) = "Ven"
    xlWorkSheet.Cells(2, 3) = "PJN"
    xlWorkSheet.Cells(2, 4) = "DRN"
    xlWorkSheet.Cells(2, 5) = "ArvM"
    xlWorkSheet.Cells(2, 6) = "ArvN"
    xlWorkSheet.Cells(2, 7) = "DDays"

    'Here is where I populate the cells from a ListView control
    Try
    For i As Integer = 0 To Me.ListView1.Items.Count - 1
    For j As Integer = 0 To Me.ListView1.Items(i).SubItems.Count - 1
    xlWorkSheet.Cells(i + 3, j + 1) = Me.ListView1.Items(i).SubItems(j).Text
    Next
    Next
    Catch ex As IOException
    MsgBox(ex.ToString)
    End Try


    'Make the report title Red
    Dim Title_range As Excel.Range = xlWorkSheet.Range("A1", "G1")
    Title_range.Font.Bold = True
    Title_range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red)
    Title_range.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Cyan)


    ' Make the headings of cells bold and Blue.
    Dim header_range As Excel.Range = xlWorkSheet.Range("A2", "G2")
    header_range.Font.Bold = True
    header_range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Blue)
    header_range.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow)


    Tab0pnlWorking.Visible = False


    xlApp.Visible = True
    xlApp.UserControl = True


    Do While xlApp.Visible
    Application.DoEvents()
    Loop
    xlApp.Quit()


    releaseObject(xlWorkSheet)
    releaseObject(xlWorkBook)
    releaseObject(xlApp)


    End Sub

    I am assuming you saw the error screen grab in the previous posts.

    Richard

  13. #13
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Do they match on both machines? Keep in mind I'm just guessing about this...
    Please remember next time...elections matter!

  14. #14

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    I can't say whether everything matched the "dead" machine which by the way was originally a Win7pro machine then upgraded to win10 pro with the free upgrade. But yes they do match what was on this machine before the upgrade. Everything worked 100% on this machine with Windows10 Home edition. All my problems started when I upgraded to Pro version.

    As a further note I keep all my Apps on a 1TB USB hard drive so nothing changed there during the upgrade. I did remove the references and then added them back just in case the dll's were different in the pro version but that did not help.

  15. #15
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    That's what I was trying to determine. Struck out...

    Is the third line of the message box have an underscore in the name or is it my old eyes?

    .Excel._Application

    That seems odd.
    Please remember next time...elections matter!

  16. #16

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Yes your eyes are 20-20 There is an underscore but knowing if that is normal or not is WAY beyond my knowledge. I admit I had not noticed that, but even if I had, it would not have rung any bells.

  17. #17
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Please remember next time...elections matter!

  18. #18

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Thanks for the links. I read all the posts in the first link but the last post confirmed my suspicions. The thread starter in that series ended up doing a complete fresh install of Windows 10 Pro, Visual Studio 2010 Pro and Office 2016 Pro and all his other programs and files. Once done everything worked as it should.

    The second link did not work.

    I really don't want to do a complete HD scrub and start all over but it looks like that is the only way to solve the issue.

    I decided to change my logic and do a Late Bind method. It is not the ideal choice but it does work and my app compiles and runs as it should. The positive there is that doing a late bind will work with any version that is installed on the clients machine. Currently not an issue but with around 15 users I can foresee a time when some will upgrade to a newer version of Office and others won't.

    Some good in all bad I guess.
    Last edited by RStratton; Feb 14th, 2018 at 05:31 PM.

  19. #19
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    I have no idea how to attach the code but if you tell me how to do it I'll show you my work around..
    All you have to do is Click on the "#" on the toolbar and then insert your code between the tags.

    You can also highlight your code then press "#"


    I'm glad late binding works for you and I understand not wanting to go through all the work of a fresh reinstall of everything. But your machine has a problem and I'd be worried this type of problem will happen again. Sometimes it's just best to bite the bullet.

  20. #20

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    57

    Re: VB.Net app will not load Excel after upgrading from Windows 10 home to Windows 10

    Yes I agree there is something wrong here and I'm guessing it is in the registry somewhere. I want to get this updated version to my client as I have added a number of new features. Once it is installed there and I get the thumbs up I will clean the hard drive and start everything fresh.

    I have included a sample report sub and put it between the code tags.

    Hope it worked.



    Code:
    Private Sub SendTheReportToExcel()
    
            'First check for an instance of Excel running as a process. If one is found then kill it.
            Do
                P = Process.GetProcessesByName("Excel")
                If P.Length > 0 Then
                    'Process is running
                    For Each Process In P
                        Try
                            Process.Kill()
                        Catch ex As Exception
                        End Try
                    Next
                Else
                    'Process is not running
                End If
            Loop While P.Length > 0
    
    
            'Create the Excel process object
            xlApp = CreateObject("Excel.Application")
            ' Late bind an instance of an Excel workbook.
            xlWorkBook = xlApp.Workbooks.Add()
            ' Late bind an instance of an Excel worksheet.
            xlWorkSheet = xlWorkBook.Worksheets(1)
            xlWorkSheet.Activate()
    
    
            'Set columnwidths
            xlWorkSheet.Range("A:D").EntireColumn.ColumnWidth = 25
            xlWorkSheet.Range("E:E").EntireColumn.ColumnWidth = 50
            'xlWorkSheet.Range("A:E").EntireColumn.HorizontalAlignment = Excel.Constants.xlLeft  '.xlRight
            xlWorkSheet.Range("A:E").EntireColumn.NumberFormat = "@"
    
    
    
    
            'Enter the report name and date
            xlWorkSheet.Cells(1, 2) = UCase(ReportName)
            xlWorkSheet.Cells(1, 4) = "REPORT DATE  " & MySQL_Date_Format(DateTime.Today)
    
    
            'Enter the report column headings
            xlWorkSheet.Cells(2, 1) = "DR #"  'A
            xlWorkSheet.Cells(2, 2) = "DR Scnd"    'B
            xlWorkSheet.Cells(2, 3) = "Inv #"   'C
            xlWorkSheet.Cells(2, 4) = "Inv Scnd"   'D
            xlWorkSheet.Cells(2, 5) = "Ven"   'E
    
    
            'Enter the report data
            Try
                For i As Integer = 0 To Me.ListView1.Items.Count - 1
                    For j As Integer = 0 To Me.ListView1.Items(i).SubItems.Count - 1
                        xlWorkSheet.Cells(i + 3, j + 1) = Me.ListView1.Items(i).SubItems(j).Text
                    Next
                Next
            Catch ex As IOException
                MsgBox(ex.ToString)
            End Try
    
    
            'Make the report title Bold Red with a cyan background
            Dim Title_range As Object = xlWorkSheet.Range("A1", "H1")
            Title_range.Font.Bold = True
            Title_range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red)
            Title_range.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Cyan)
    
    
            ' Make the headings of cells Bold Blue with a Yellow background
            Dim Header_Range As Object = xlWorkSheet.Range("A2", "H2")
            Header_Range.Font.Bold = True
            Header_Range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Blue)
            Header_Range.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow)
            Tab0pnlWorking.Visible = False
    
    
            'Save the file using the report name defined earlier
            Try
                xlWorkBook.saveas(ReportName)
            Catch ex As Exception
            End Try
    
    
            'The workbook was saved as file so kill the process
            Do
                P = Process.GetProcessesByName("Excel")
                If P.Length > 0 Then
                    'Process is running SO Kill it
                    For Each Process In P
                        Try
                            Process.Kill()
                        Catch ex As Exception
                        End Try
                    Next
                Else
                    'Process is not running
                End If
            Loop While P.Length > 0
    
    
            'Do some system garbage collecting
            Try
                GC.Collect()
                GC.WaitForPendingFinalizers()
                Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkSheet)
                Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkBook)
                Runtime.InteropServices.Marshal.FinalReleaseComObject(xlApp)
                xlApp = Nothing
            Catch ex As Exception
            End Try
    
    
            'Now start Excel with the document saved earlier
            Using FileProcess As Process = Process.Start("C:\Users\" & sysUserName & "\Documents\" & ReportName & ".xlsx")
                Try
                    FileProcess.WaitForExit()
                    FileProcess.Dispose()
                Catch ex As Exception
                End Try
            End Using
    
    
            'Excel saves files to the Documents folder by default so we need to delete the report from the users documents folder
            Dim path As String = "C:\Users\" & sysUserName & "\Documents\" & ReportName & ".xlsx"
            If File.Exists(path) Then
                File.Delete(path)
            End If
    
    
        End Sub
    Amazing! It worked thanks for the lesson.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width