今天晚上写了个获取当前Office版本的函数(原创!)

获取当前Office版本的函数

Private Sub Command1_Click()
    MsgBox GetInstalledOfficeVersion()
End Sub

'本函数运行不需要机器上安装过Office
'经典的判断Office版本函数,原创!
'支持到Office 2003
Function GetInstalledOfficeVersion() As String
    On Error Resume Next
    Dim WD
    Dim OfficeVer As String
    OfficeVer = 0
    GetInstalledOfficeVersion = ""
    Set WD = CreateObject("Word.Application.8")
    OfficeVer = CStr(WD.Version)
    WD.quit
    If Not WD Is Nothing Then Set WD = Nothing
    If InStr(OfficeVer, "8") <> 0 Then
       GetInstalledOfficeVersion = "Office 97"
    ElseIf InStr(OfficeVer, "9") <> 0 Then
       GetInstalledOfficeVersion = "Office 2000"
    ElseIf InStr(OfficeVer, "10") <> 0 Then
       GetInstalledOfficeVersion = "Office XP 2002"
    ElseIf InStr(OfficeVer, "11") <> 0 Then
       GetInstalledOfficeVersion = "Office 2003"
    End If
    If Err.Number = 424 Then
       Err.Clear
       GetInstalledOfficeVersion = "没有安装 Microsoft Office"
    End If
End Function


'-------------------------------------------
' 转载请注明出处
' 作者:唐细刚
' 邮箱:[email protected]
'-------------------------------------------

你可能感兴趣的:(function,String,XP,Microsoft,command,Office)