Results 1 to 13 of 13
  1. #1
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,378
    Thanks
    207
    Thanked 829 Times in 762 Posts

    VBA object model error

    Hey Y'all,

    With Windows 8 Pro 64 bit with Office 2010 Pro 32 bit.

    When I use Excel VBA to query the OS Version via : ?application.OperatingSystem
    The response is : Windows (32-bit) NT 6.02

    With Windows 7 HP 64 bit with Office 2003 Pro 32 bit.

    The response is: Windows (32-bit) NT 6.01

    It would seem that MS can't tell the difference between the bitness of Office and Windows.

    I'd be interested in the response from someone running 64 bit Office.

    Note: Neither Word or Access support this method/property.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    196
    Thanks
    4
    Thanked 46 Times in 38 Posts
    Yep, it looks like the Application.OperatingSystem method has a bug (and it's still there in Excel 2013). The workaround is the function shown in the reply to http://www.mrexcel.com/forum/excel-q...lications.html, checking whether the environment variable ProgramW6432 exists. I've tested that in Windows 8 (64-bit) with Office 2013 (32-bit), and in Windows XP (32-bit) with Office 2003 (32-bit). Sorry, I don't have Office 64-bit installed anywhere.

    In Word VBA, you can use Application.System.OperatingSystem, which returns "Windows NT", and Application.System.Version, which returns "6.1" on Windows 7 and "6.2" on Windows 8. I don't see anything similar in Access VBA, but I'm not familiar with it and might just be missing it.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    861
    Thanks
    0
    Thanked 10 Times in 9 Posts
    In Word you can use System.OperatingSystem and System.Version. I believe the results are similar to what you're seeing in Excel.

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,378
    Thanks
    207
    Thanked 829 Times in 762 Posts
    Thanks Guys!

    Here's the results of my explorations.

    VBA Find Operating System Version

    Excel: Application.OperatingSystem
    (Note: if called from 32bit Office returns
    32-bit even though the OS is 64-bit!)
    Application.Version {14.0} = Office 2010
    Environ("Programw6432") {C:\Program Files} = 64-bit Windows

    Word: System.OperatingSystem {Windows NT}
    System.Version {6.2} = Win 8
    Environ("Programw6432") {C:\Program Files} = 64-bit Windows

    Access:
    Environ("Programw6432") {C:\Program Files} = 64-bit Windows
    Application.Version {14.0} = Office 2010

    Code:
    '                         +-------------------------+             +----------+
    '-------------------------|    AccessVersionID()    |-------------| 05/23/10 |
    '                         +-------------------------+             +----------+
    '*** Code to determing the Version of Access which is running
    
    Public Function AccessVersionID() As String
    
    
      Select Case SysCmd(acSysCmdAccessVer)
            Case 7: AccessVersionID = "95"
            Case 8: AccessVersionID = "97"
            Case 9: AccessVersionID = "2000"
            Case 10: AccessVersionID = "2002"
            Case 11: AccessVersionID = "2003"
            Case 12: AccessVersionID = "2007"
            Case 14: AccessVersionID = "2010"
            Case Else: AccessVersionID = "Unknown"
      End Select
    
    End Function            'AccessVersionID()

    PowerPoint: Application.OperatingSystem
    (Note: if called from 32bit Office returns
    32-bit even though the OS is 64-bit!)
    Environ("Programw6432") {C:\Program Files} = 64-bit Windows
    Application.Version {14.0} = Office 2010

    Outlook:
    Environ("Program6432") {C:\Program Files} = 64-bit Windows
    Application.Version {14.0.0.6131} = Office 2010

    All:

    This link uses Windows API calls to get the version and will work in
    all programs.

    http://access.mvps.org/access/api/api0055.htm

    Here's another version.

    http://social.msdn.microsoft.com/Forums/en-US/accessdev/thread/85403a60-bad3-47b3-b0ec-74681e370e7b/




    My Version
    Universal Windows Version Finder:
    Code:
    Option Explicit
    '                        +--------------------------+             +----------+
    '------------------------|Windows Function Type Defs|-------------| 08/11/05 |
    '                        +--------------------------+             +----------+
    
    Type OSVERSIONINFO   '  148 Bytes
            dwOSVersionInfoSize As Long
            dwMajorVersion As Long
            dwMinorVersion As Long
            dwBuildNumber As Long
            dwPlatformId As Long
            szCSDVersion As String * 128
    End Type
    
    '                     +-----------------------------+             +----------+
    '---------------------|Windows Function Declarations|-------------| 08/11/05 |
    '                     +-----------------------------+             +----------+
    
    Declare Function GetVersionEx& Lib "kernel32" _
    Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO)
    
    
    '                        +----------------------+                +----------+
    '------------------------| zFindWindowsVersion()|----------------| 04/12/13 |
    '                        +----------------------+                +----------+
    ' Returns a string indicating the Windows Version
    
    Function zFindWindowsVersion() As String
    
       Dim tOSVer As OSVERSIONINFO
       Dim zOsVer As String
       
       tOSVer.dwOSVersionInfoSize = 148
       GetVersionEx& tOSVer
       
       With tOSVer
       
           Select Case .dwPlatformId
             
             Case 1:
           
               Select Case .dwMajorVersion
                 Case 4:
                     Select Case .dwMinorVersion
                           Case 0: zOsVer = "Windows 95"
                           Case 10: zOsVer = "Windows 98"
                           Case 90: zOsVer = "Windows ME"
                     End Select
                 Case 5: zOsVer = _
                      IIf(.dwMinorVersion = 1, "Windows XP", "Windows 2000")
               End Select
        
             Case 2:
               Select Case .dwMajorVersion
                 Case 4: zOsVer = "Windows NT4"
                 Case 5: zOsVer = _
                      IIf(.dwMinorVersion = 1, "Windows XP", "Windows 2000")
                 Case 6:
                        Select Case .dwMinorVersion
                           Case 0: zOsVer = "Vista"
                           Case 1: zOsVer = "Windows 7"
                           Case 2: zOsVer = "Windows 8"
                        End Select
                        zOsVer = zOsVer & IIf(Environ("ProgramW6432") <> "", " 64-Bit", " 32-Bit")
               End Select
            
             End Select
           
       End With      'tOSVer
       
       zFindWindowsVersion = zOsVer
       
    End Function             'zFindWindowsVersion
    I'd really appreciate it if someone with 64 bit office could test the office version info and someone with 32 bit Win 7 and/or 8 would test the other code. Yes I know my version doesn't test for all versions of windows but it can be easily modified to include older versions using the info in the links.

    Last edited by RetiredGeek; 2013-04-21 at 11:26.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,942
    Thanks
    0
    Thanked 203 Times in 184 Posts
    You might also try:
    Code:
    Sub TestOfficeBits()
    Dim StrBase As String
    StrBase = "HKEY_CLASSES_ROOT\OfficeCompatible.Application."
    With System
      If Trim(.PrivateProfileString("", StrBase & "x86\CurVer", "")) <> "" Then
        MsgBox .OperatingSystem & " " & .Version & ", 32-bit Office"
      ElseIf Trim(.PrivateProfileString("", StrBase & "x64\CurVer", "")) <> "" Then
        MsgBox .OperatingSystem & " " & .Version & ", 64-bit Office"
      End If
    End With
    End Sub
    This should tell you whether Office is running in 32-bit mode or 64-bit mode.
    Last edited by macropod; 2013-04-14 at 10:39.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. The Following User Says Thank You to macropod For This Useful Post:

    RetiredGeek (2013-04-14)

  7. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,378
    Thanks
    207
    Thanked 829 Times in 762 Posts
    Paul,

    I get a compile error on System, Variable not defined, with Office 2010 Excel. Is there a library necessary?
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  8. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,942
    Thanks
    0
    Thanked 203 Times in 184 Posts
    I developed & tested the code in Word only; it didn't occur to me that Excel (and maybe other Office Apps) wouldn't know what System is! For those, a Reference to Word will resolve the issue.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #8
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,378
    Thanks
    207
    Thanked 829 Times in 762 Posts
    Paul,

    Still no love in Excel.
    429Error.JPG

    Same results in Outlook & Access.
    Last edited by RetiredGeek; 2013-04-14 at 20:12.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  10. #9
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,942
    Thanks
    0
    Thanked 203 Times in 184 Posts
    I think you might need to re-start Excel (or maybe even repair your Office installation) ...
    See: http://support.microsoft.com/kb/244264 http://support.microsoft.com/kb/828550
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  11. #10
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,378
    Thanks
    207
    Thanked 829 Times in 762 Posts
    Paul,

    Didn't need to reset Office but what I did need was:
    Code:
    Option Explicit
    
    Sub TestOfficeBits()
    Dim StrBase As String
    
    Dim oWordApp As Object                          '<-----
    Set oWordApp = CreateObject("Word.Application") '<-----
    
    StrBase = "HKEY_CLASSES_ROOT\OfficeCompatible.Application."
    
    With oWordApp.System                            '<------
    
      If Trim(.PrivateProfileString("", StrBase & "x86\CurVer", "")) <> "" Then
        MsgBox .OperatingSystem & " " & .Version & ", 32-bit Office"
      ElseIf Trim(.PrivateProfileString("", StrBase & "x64\CurVer", "")) <> "" Then
        MsgBox .OperatingSystem & " " & .Version & ", 64-bit Office"
      End If
    End With
    
    Set oWordApp = Nothing                          '<------
    
    End Sub
    As explained later in the referenced article. I used late binding in this example. It's a bit much but it works.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  12. #11
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    196
    Thanks
    4
    Thanked 46 Times in 38 Posts
    Paul, when I run the code in Excel 2013 with a reference to the Word 15.0 library, I get the same 429 error unless I start any version of Word first. If I then shut down Word and run the macro again, I get an error 462, "The remote server machine does not exist or is unavailable." After that happens, the 462 error persists even if I start Word again.

    This might have something to do with my having four versions of Word on the machine, and the resulting confusion in the registry over which one might be "the" COM server for the Word library, but the behavior is the same for all versions.

  13. #12
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,942
    Thanks
    0
    Thanked 203 Times in 184 Posts
    See RG's update (post #10)
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  14. #13
    Bronze Lounger
    Join Date
    Mar 2002
    Location
    Newcastle, UK
    Posts
    1,515
    Thanks
    30
    Thanked 177 Times in 172 Posts
    Hi RG

    ..just for completeness, your Function AccessVersionID() As String
    ...
    Case 15: AccessVersionID = "2013"
    Case Else: AccessVersionID = "Unknown"
    ...

    zeddy

  15. The Following User Says Thank You to zeddy For This Useful Post:

    RetiredGeek (2013-04-21)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •