Question

I wanna check the window version on different comp thus to do different task on MS word 2007 vba. i tried this code which i applied on ms excel 2007 vba and is working, but not on MS word 2007 vba.

Dim TheOS As String
Dim WinType As String
TheOS = Application.OperatingSystem
MsgBox ("TheOS ")

On the ms word 2007 vba, it reurn a compile error:method or data member not found. what do i need?

Was it helpful?

Solution

If you want vba code that can be used all over the office products WMI is one solution.

The thing with Application.System.OperatingSystem that its not returning anything interesting.

Application.System.Version is usable. But I use the WMI to give me the correct information.

 Sub test()
    Dim info As System
    'Well everything is windows NT today..
    Debug.Print Application.System.OperatingSystem
    'Short version string MajorVersion.MinorVersion
    Debug.Print Application.System.Version

    Dim objWMI As Object
    Dim objSystems As Object
    Dim objOs As Object

    Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set objSystems = objWMI.ExecQuery("Select * from Win32_OperatingSystem")

    For Each objOs In objSystems
        Debug.Print objOs.Name 'Full name as in OS startup screen
        Debug.Print objOs.Caption ' Human readable name
        Debug.Print objOs.Version ' the correct windows version string
    Next

    Set objOs = Nothing
    Set objSystems = Nothing
    Set objWMI = Nothing

End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top