'Microsoft Office 产品对版本号使用下面的语法: 'aa.bbbb.cccc '此数字代表下列三个项目: 'aa: Office 的版本 'bbbb:程序的可执行文件的版本。例如 Excel.exe 文件。 'cccc: Mso.dll 文件的版本 '知道这层意思就可以很容易获得Excel的版本了: Private Type VS_FIXEDFILEINFO dwSignature As Long dwStrucVersion As Long dwFileVersionMSl As Integer dwFileVersionMSh As Integer dwFileVersionLSl As Integer dwFileVersionLSh As Integer dwProductVersionMSl As Integer dwProductVersionMSh As Integer dwProductVersionLSl As Integer dwProductVersionLSh As Integer dwFileFlagsMask As Long dwFileFlags As Long dwFileOS As Long dwFileType As Long dwFileSubtype As Long dwFileDateMS As Long dwFileDateLS As Long End Type Private Declare Function GetFileVersionInfo _ Lib "Version.dll" Alias _ "GetFileVersionInfoA" (ByVal lptstrFilename _ As String, ByVal dwHandle As Long, ByVal _ dwLen As Long, lpData As Any) As Long Private Declare Function _ GetFileVersionInfoSize Lib "Version.dll" _ Alias "GetFileVersionInfoSizeA" (ByVal _ lptstrFilename As String, lpdwHandle As _ Long) As Long Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" (dest As Any, src As _ Long, ByVal length As Long) Private Declare Function VerQueryValue Lib _ "Version.dll" Alias "VerQueryValueA" _ (pBlock As Any, ByVal lpSubBlock As String, _ lplpBuffer As Any, puLen As Long) As Long Public Function GetVersionInfo(ByVal sFile As _ String) As String Dim lDummy As Long Dim sBuffer() As Byte Dim lBufferLen As Long, lVerPointer As Long Dim lVerBufferLen As Long Dim udtVerBuffer As VS_FIXEDFILEINFO GetVersionInfo = "N/A" lBufferLen = GetFileVersionInfoSize(sFile, _ lDummy) If lBufferLen > 0 Then ReDim sBuffer(lBufferLen) If GetFileVersionInfo(sFile, 0&, _ lBufferLen, sBuffer(0)) <> 0 Then If VerQueryValue(sBuffer(0), _ "\", lVerPointer, lVerBufferLen) _ <> 0 Then CopyMemory udtVerBuffer, ByVal _ lVerPointer, Len(udtVerBuffer) With udtVerBuffer GetVersionInfo = .dwFileVersionLSh End With End If End If End If End Function Sub Excelversion() '获得Excel的详细版本号 Dim ExcelName As String, MsoName As String ExcelName = Application.Path & "\Excel.exe" MsoName = "C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSO.Dll" MsgBox "Excel版本号是" & VBA.Val(Application.Version) & "." & _ GetVersionInfo(ExcelName) & "." & _ GetVersionInfo(MsoName) End Sub '其它Office产品以此类推
测试结果:我的Excel版本号是11.5612.5606 关于Excel 的截屏
[此贴子已经被作者于2008-1-28 17:40:28编辑过] |