I have already some code to check if Excel is installed. But I recently bought a new computer and I have excel installed but for some reason my code stopped working. I've looked at the code and I don't see what could be wrong. I'm completely sure that I have excel installed in my computer.
Public ReadOnly Property IsExcelInstalled As Boolean
Get
Try
Dim registryKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("Excel.Application")
Dim result As Boolean = Not Equals(registryKey, Nothing)
registryKey.Close()
Return result
Catch ex As Exception
MessageBox.Show("Excel is not installed on the computer. The files could not be imported.", "Import File", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Return False
End Try
End Get
End Property
I appreciate any help regarding this. Could it be that this piece of code is outdated?
-- Update: After trying a bit more it seems that this function is working the problem is that I don't have excel/word installed. Although it is on my computer and I can use it, seems it is not installed in the computer. I can't find it if I go to control panel -> Uninstall programs. The solution was to go to microsoft's webpage download microsoft office 365 and install it on my computer. After that the above code was able to find the registryKey. Does anyone know what this could be? And how can I prevent this from happening?