使用VBA查找MS Office修订版和构建版本

时间:2015-07-30 08:14:23

标签: vba ms-office version

可以使用Application.Version找到办公室应用程序的主要版本和次要版本

返回示例:

15.0 = Office 2013
12.0 = Office 2007

我需要office应用程序的修订版本和版本,例如:

Microsoft Office PowerPoint 2007原件:major.minor: 12.0 revision.build: 4518.1014

Microsoft Office PowerPoint 2007 SP2:major.minor: 12.0 revision.build: 6425.1000

问题:有没有办法找到办公室应用程序的修订版本和版本使用VBA

更新问题:我的命名约定错误 - 寻找办公室应用程序的修订和构建版本,而不是次要版本。

2 个答案:

答案 0 :(得分:4)

VBA没有直接执行此功能的功能,您必须编写一个函数来执行此操作:

Public Sub test()
    Dim version As String
    Dim chkref As Object

    ' List of references
    For Each chkref In ThisWorkbook.VBProject.References
        version = RetrieveDllVersion(chkref.fullpath)
        major = RetrievePart(version, 0)
        majorup = RetrievePart(version, 1)
        minor = RetrievePart(version, 2)
        minorup = RetrievePart(version, 3)

        MsgBox chkref.Name & " : " & major & "." & majorup & "." & minor & "." & minorup
    Next
End Sub

Private Function RetrieveDllVersion(ByVal dll As String) As String
  Dim fso As Object 'Scripting.FileSystemObject
  Set fso = CreateObject("Scripting.FileSystemObject")
  RetrieveDllVersion = fso.GetFileVersion(dll)
End Function

Private Function RetrievePart(ByVal version As String, ByVal pos As Integer) As String
    RetrievePart = Split(version, ".")(pos)
End Function

在chkref.name上过滤Excel / Office / Word

答案 1 :(得分:2)

替代方案摘要:

Application.Version                                             "16.0"
Application.Build                                               "16.0.8431"
Application.BuildFull                                           "16.0.8431.0"

CreateObject("Scripting.FileSystemObject") _
    .GetFileVersion(Application.Path & "\WINWORD.exe")          "16.0.8431.2280"