VB.NETでインストールされているExcelのバージョンの判断をしたい
通常はExcelのアカウント>>Excelのバージョン情報で判断できるが
vb.net中で判断する方法
Imports System.Reflectionを宣言して
Imports System.Reflection
Public Class Form1
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim errflg = False
Dim classType As Type = Nothing
Dim Exapp As Object = Nothing
Try
errflg = False
classType = Type.GetTypeFromProgID("Excel.Application")
Exapp = Activator.CreateInstance(classType)
Catch ex As Exception
errflg = True
End Try
If errflg = True Then
Try
errflg = False
classType = Type.GetTypeFromProgID("Excel.Application.16")
Exapp = Activator.CreateInstance(classType)
Catch ex As Exception
errflg = True
End Try
End If
If errflg = True Then
Try
errflg = False
classType = Type.GetTypeFromProgID("Excel.Application.15")
Exapp = Activator.CreateInstance(classType)
Catch ex As Exception
errflg = True
End Try
End If
If errflg = True Then
MsgBox("Excel verエラー 未対応です", MsgBoxStyle.Information)
Exit Sub
End If
If Exapp Is Nothing Then
MsgBox("No Excel", MsgBoxStyle.Information)
Exit Sub
End If
Dim VerObj As Object = Exapp.[GetType]().InvokeMember("Version", BindingFlags.GetProperty, Nothing, Exapp, Nothing)
Dim vesion As String = VerObj.ToString()
MsgBox(vesion, MsgBoxStyle.Information)
End Sub
End Class