检查用户计算机中是否安装了Excel

时间:2019-08-08 11:45:14

标签: excel vb.net

我已经有一些代码来检查是否已安装Excel。但是我最近买了一台新计算机,并安装了excel,但是由于某种原因我的代码停止工作。我看过代码,看不出有什么问题。我完全确定自己的计算机上已经安装了excel。

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

我对此表示感谢。难道这段代码已经过时了?

-更新: 经过更多尝试后,似乎该功能正在起作用,问题是我没有安装excel / word。尽管它在我的计算机上并且可以使用,但似乎它尚未安装在计算机上。如果转到控制面板->卸载程序,我找不到它。 解决方案是转到Microsoft的网页下载Microsoft Office 365并将其安装在我的计算机上。之后,上面的代码能够找到RegistryKey。 有谁知道这可能是什么?以及如何防止这种情况发生?

0 个答案:

没有答案