In Microsoft Project for Windows, use Windows Management Instrumentation (WMI) from VBA to read the operating system’s name, version, and build. The example below uses late-bound WMI, so it does not require an added VBA reference or Windows API declarations.
VBA code to read the Windows version
In Project, press Alt+F11 to open the Visual Basic Editor. Choose Insert > Module, paste the code into the module, and run ShowWindowsVersion. It displays the Windows information in a message box. You can also call WindowsVersionDetails from another macro and use the returned text.
Option Explicit
Public Function WindowsVersionDetails() As String
Dim service As Object
Dim results As Object
Dim item As Object
On Error GoTo ReadFailed
' Connect to WMI on the computer running Project.
Set service = GetObject("winmgmts:\\.\root\cimv2")
Set results = service.ExecQuery( _
"SELECT Caption, Version, BuildNumber FROM Win32_OperatingSystem")
For Each item In results
WindowsVersionDetails = CStr(item.Caption) & _
" | version " & CStr(item.Version) & _
" | build " & CStr(item.BuildNumber)
Exit Function
Next item
WindowsVersionDetails = "Windows information was not returned."
Exit Function
ReadFailed:
WindowsVersionDetails = "Windows information could not be read (error " & _
CStr(Err.Number) & ")."
End Function
Public Sub ShowWindowsVersion()
MsgBox WindowsVersionDetails(), vbInformation, "Windows version"
End Sub
Save a copy of the Project file before running any macro. VBA macros cannot be undone with Ctrl+Z, even when the macro’s main purpose is to display information. This particular example only reads system details and shows them; it does not change the project plan.
What the returned values mean
The result is assembled from three properties of the WMI Win32_OperatingSystem class:
Captionis the Windows product description, such as a Windows edition name.Versionis the operating system’s technical version string.BuildNumberis the Windows build identifier.
A sample result might look like Microsoft Windows 11 Pro | version 10.0.22631 | build 22631. That is an example, not a value every Windows 11 computer will return; feature updates and servicing can change the build. The important detail is that Windows 11 can report a technical version beginning with 10.0. Do not conclude that a computer is running Windows 10 just because that number appears. Use the caption and build together, and avoid treating a hard-coded build list as a permanent classification system.
WMI reports the computer on which the code is running. It does not reveal which Windows version was used to create the Project file, nor does it identify the operating system of a colleague who later opens that file.
How the WMI method works
WMI is a Windows management service that exposes information about the local computer through classes and properties. The code connects to the local computer’s root\cimv2 namespace, asks for three fields from Win32_OperatingSystem, and reads the returned record. The period in the connection string represents the local computer.
The variables are declared as Object rather than as WMI-specific types. This is called late binding: VBA resolves the COM objects when the code runs. As a result, you do not need to open Tools > References and select a WMI library. That makes the example easier to move between compatible Windows installations and avoids a common “Missing” reference problem.
The error handler is included because WMI access can fail—for example, if the service is unavailable or a system policy blocks the request. Instead of stopping on an unhandled runtime error, the function returns a short message containing the VBA error number. That message is useful for basic diagnosis, but it is not a full security or WMI diagnostic report.
Running and adapting the macro in Project
After inserting the code in a standard module, place the cursor inside ShowWindowsVersion and press F5, or return to Project and run the macro from the Macro dialog. In the VBA editor, Ctrl+G opens the Immediate window, where you can also print the function’s result with ? WindowsVersionDetails(). On a Mac, keyboard shortcuts and available VBA features can differ, but Microsoft Project’s VBA environment is intended for the Windows desktop application; the WMI connection shown here is Windows-specific.
For a larger automation task, use the function’s text result rather than displaying a message box. For example, another procedure could write the string to a log file or compare it with an approved environment before continuing. If you add logic that makes decisions based on Windows versions, define exactly which editions and builds are supported and how updates will be handled. A label check alone can be brittle when Microsoft changes the wording or servicing changes the build.
Macros must be permitted by the organization’s Project or Office security settings. If Project blocks the macro, follow your organization’s approved process for enabling or signing trusted macros rather than lowering macro security globally. This WMI sample does not require enabling “Trust access to the VBA project object model”; that setting is for code that programmatically inspects or edits VBA projects, which this example does not do.
WMI compared with other ways to identify Windows
WMI is a practical choice when a Project macro needs a readable local OS name and version without API declarations. Other methods exist, but they answer slightly different needs:
- Windows API calls: APIs such as version-reporting functions can provide version details, but declarations must account for 32-bit and 64-bit VBA, and some version APIs can return compatibility-related results depending on application manifests. That extra complexity is usually unnecessary for a simple diagnostic macro.
- Registry values: Windows stores product and build information under the Windows NT current-version registry key. Registry values and their interpretation can vary by Windows release and registry view. If an application has a specific registry-based requirement, verify the exact value and 32-/64-bit behavior on supported systems instead of assuming a product label is universal.
- Manual inspection: A user can check Windows Settings > System > About. This is suitable for a one-time check, but it is not automated and may be inconvenient when collecting information from several workstations.
For a macro that only needs to know whether it is running on Windows, a full version query may be more information than necessary. Conversely, if a compliance or deployment tool needs a carefully validated Windows release classification, use a documented policy and test it against the organization’s supported devices rather than relying on one caption string.
Common misunderstandings and limitations
A frequent mix-up is confusing the version of Project with the version of Windows. An application version property, when used in Project VBA, describes the Project application; it is not an operating-system query. A Windows version check must obtain data from Windows itself, as the WMI code does.
Another misconception is that the version string alone always maps directly to a consumer-facing Windows name. Windows 10 and Windows 11 share the technical major and minor version number 10.0, so a test such as “version equals 10.0, therefore Windows 10” is not reliable. The returned caption and build provide more context, but build numbers also change. If a macro needs a yes/no decision, write and maintain a deliberate rule for the specific systems that matter.
This code is also not a remote inventory tool. The local connection string targets the machine running Project. Querying another computer requires a different WMI connection and suitable network permissions, which should be designed and secured separately. Do not assume that a workbook or Project file carries a trustworthy record of the computer where it was last saved.
Project, Windows, and platform compatibility
The sample is for the desktop version of Microsoft Project running on Windows. WMI is a Windows technology, so the connection and class query are not portable to a non-Windows environment. Project for the web is a browser-based service and does not run VBA macros. If you are automating work in a web-based project service, you need an interface supported by that service rather than this desktop VBA approach.
Because the code uses late-bound COM objects rather than Windows API declarations, it avoids the usual PtrSafe and pointer-size issues associated with API code in 64-bit Office. It still depends on Windows WMI being available and accessible. If you distribute the macro to other machines, test it under the same Project edition, Windows configuration, and macro-security policy that recipients will use.
Frequently Asked Questions
Does this macro return Windows 10 or Windows 11?
It returns Windows’ caption, technical version, and build. The caption may identify the product name, while the technical version can begin with 10.0 for either Windows 10 or Windows 11. Use more than the major/minor version when identifying the release.
Do I need to add a WMI reference in VBA?
No. The example uses late binding by declaring the WMI objects as Object. It connects at run time, so you do not need to select a WMI library in Tools > References.
Why does the macro show an error instead of a version?
WMI may be unavailable, blocked, or unable to return the requested data. The function returns a message with the VBA error number. Check whether the macro is allowed to run, then ask your administrator about WMI availability or policy if the issue persists.
Can I use this code to check another computer?
Not as written. The connection targets the local computer. Remote WMI access requires a different connection and appropriate network, firewall, and permission settings; those should be configured under your organization’s security rules.
Will the code work in Project for the web or on a Mac?
No. Project for the web does not run VBA, and this query relies on Windows WMI. Use the Windows desktop version of Project for this method.
Related
- Excel Turn Off Page Break Lines on Screen
- Excel Page Break Dotted Lines: How to Turn Them Off
- Excel: Turn Off Page Break Preview and Restore Normal View
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Mid: How the Function WorksIn Excel VBA, Mid returns part of a string, starting at a position you specify; positions begin at…
- Excel VBA FindNext: How to Find the Next MatchIn Excel VBA, use Range.FindNext to move from one match to the next after starting a search with…
- VBA Editor in Excel: Where to Find It and How to OpenIn Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor (VBE), where you…
- Excel VBA Active Workbook: Meaning and ExamplesIn Excel VBA, ActiveWorkbook refers to the workbook currently active in Excel’s window. Use it when a macro…
- Excel VBA AutoFilter Method Failed? Causes and FixesYes—“AutoFilter method of Range failed” is usually a VBA runtime error caused by an invalid or unsuitable range,…
- Find Unique Values in VBA: Methods and ExamplesTo find distinct values in VBA, read the source cells into a Scripting.Dictionary and add a value only…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.