[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.
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
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)
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.
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
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.
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.
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.
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
'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()
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.
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.
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.
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.
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