gpt4 book ai didi

excel - vba Excel 中的 Office 版本和操作系统错误

转载 作者:行者123 更新时间:2023-12-04 22:12:40 24 4
gpt4 key购买 nike

我正在使用 Windows 11 在 VBA Excel 365 中运行此代码

Sub test()
Dim sBuild As String, sOP As String, sVersion As String

sBuild = Application.Build
sOP = Application.OperatingSystem
sVersion = Application.Version
MsgBox "Operating System " & sOP & " with Office version " & sVersion & " Build " & sBuild

End Sub
但是,我收到此消息“操作系统 Windows(64 位)NT 10.00 和 Office 版本 16.0 Build 15028”
属性 Application.Version 和 Application.OperatingSystem 显示的结果与我在 Excel 2016 中运行并使用 Windows 10 时显示的结果相同。
有什么建议可以获取真正的 Office 和 Windows 版本吗?
谢谢你。
曼努埃尔

最佳答案

上述评论中的此链接适用于 Office (Check the application version in modern office)。
我在 Windows 上使用它:

Function GetWindowsInfo() As String
Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")
Dim RegKeyProduct As String
RegKeyProduct = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName"
Dim ProductName As String
ProductName = oShell.RegRead(RegKeyProduct)
Dim VersionBuildNumbers(1 To 4) As Variant
Dim RegKeyMajor As String
RegKeyMajor = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentMajorVersionNumber"
VersionBuildNumbers(1) = oShell.RegRead(RegKeyMajor)
Dim RegKeyMinor As String
RegKeyMinor = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentMinorVersionNumber"
VersionBuildNumbers(2) = oShell.RegRead(RegKeyMinor)
Dim RegKeyBuild As String
RegKeyBuild = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentBuildNumber"
VersionBuildNumbers(3) = oShell.RegRead(RegKeyBuild)
If VersionBuildNumbers(3) >= 22000 Then
ProductName = Replace(ProductName, "10", "11")
End If
Dim RegKeyUBR As String
RegKeyUBR = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UBR"
VersionBuildNumbers(4) = oShell.RegRead(RegKeyUBR)
Dim BuildNumber As String
BuildNumber = oShell.RegRead(RegKeyBuild) & "." & oShell.RegRead(RegKeyUBR)
Dim Bitness As String
Bitness = "32-bit"
If Len(Environ("PROGRAMFILES(x86)")) Then Bitness = "64-bit"
GetWindowsInfo = "Microsoft " & ProductName & " (" & Join(VersionBuildNumbers, ".") & ") " & Bitness
End Function

关于excel - vba Excel 中的 Office 版本和操作系统错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71785434/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com