MrExcel Message Board
Support This Site


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 30th, 2004, 07:46 PM   #1
McLaren
 
Join Date: Jul 2003
Location: California
Posts: 111
Default Not sure how to implement OS Version Info.

I am trying to dictate a file path based on OS Version, but am not sure how to do it exactly. I found this code for determining the OS, and I believe it goes in a module, but how do I access the results for my CommandButton?
Any help is appreciated.

Function OS_Version() As String
Dim Os As OSVERSIONINFO
Dim m As Long
Dim MjV As Long
Dim PId As Long
Dim MnV As Long

Os.dwOSVersionInfoSize = Len(Os)
m = GetVersionEx(Os)
MjV = Os.dwMajorVersion
PId = Os.dwPlatformId
MnV = Os.dwMinorVersion

If PId = 2 Then
'// NT,2000,XP
Select Case Os.dwMajorVersion
Case Is = 3
OS_Version = " Windows NT 3." & Os.dwMinorVersion
Case Is = 4
OS_Version = " Windows NT 4 "
Case Is = 5
Select Case Os.dwMinorVersion
'// win 2000
Case Is = 0
OS_Version = " Windows Windows 2000 "
'// win XP or win .NET server
Case Is = 1
OS_Version = " Windows XP "
Case Else
OS_Version = " Windows .NET Server "
End Select
End Select
End If

If PId = 1 Then
If MnV = 10 Then OS_Version = " Windows 98 "
If MnV = 0 Then OS_Version = " Windows 95 "
If MnV = 90 Then OS_Version = " Windows ME "
End If

End Function
McLaren is offline   Reply With Quote
Old Mar 30th, 2004, 08:03 PM   #2
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,738
Default Re: Not sure how to implement OS Version Info.

Something like

Code:
Private Sub CommandButton1_Click()
   MsgBox "The OS is : " & OS_Version
End Sub
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Mar 30th, 2004, 08:15 PM   #3
McLaren
 
Join Date: Jul 2003
Location: California
Posts: 111
Default Re: Not sure how to implement OS Version Info.

Opps, sorry. I was looking for something like this. I am only trying to get the path to the desktop. However when I used this code MSWord opened up asking me where to save the file, so I wasn't sure what I was doing wrong.

If PId = 2 Then
appWD.ActiveDocument.SaveAs FileName:="C:\Documents and Settings\All Users\Desktop\bores.tap", FileFormat:=wdFormatText
Else
appWD.ActiveDocument.SaveAs FileName:="C:\WINDOWS\Desktop\bores.tap", FileFormat:=wdFormatText
End If
McLaren is offline   Reply With Quote
Old Apr 4th, 2004, 05:07 AM   #4
McLaren
 
Join Date: Jul 2003
Location: California
Posts: 111
Default Re: Not sure how to implement OS Version Info.

bump
McLaren is offline   Reply With Quote
Old Apr 4th, 2004, 08:45 AM   #5
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,208
Default

Have a look here ..... detailed sorry BUT you are looking to get Item Identifiers and Identifier Lists

http://www.xcelfiles.com/Shell32_00.html

Link explains it ...

Code:
Option Explicit

Private Type SHITEMID
    cb   As Long
    abID As Byte
End Type

Private Type ITEMIDLIST
    mkid As SHITEMID
End Type

Private Declare Function SHGetSpecialFolderLocation _
    Lib "shell32.dll" ( _
    ByVal hwndOwner As Long, _
    ByVal nFolder As Long, _
    pidl As ITEMIDLIST) _
As Long

Private Declare Function SHGetPathFromIDList _
    Lib "shell32.dll" _
    Alias "SHGetPathFromIDListA" ( _
    ByVal pidl As Long, _
    ByVal pszPath As String) _
As Long

Const MAX_PATH = 260
Const CSIDL_PROFILE = &H28
Const CSIDL_COMMONDESKTOP = &H0

Sub API_GetSpecialFolder()
    '// lets get the users special folder
    MsgBox "ActiveUser DeskTop" & GetSpecialfolder(SpecFolders.CSIDL_COMMONDESKTOP)
End Sub

Function GetSpecialfolder(CSIDL As Long) As String
    Dim r As Long
    Dim IDL As ITEMIDLIST
    Dim strPath As String
    
    r = SHGetSpecialFolderLocation(0, CSIDL, IDL)
    If r = 0 Then
        '// Create a buffer MAX
        strPath = Space(MAX_PATH)
        '// Get the path from the IDList
        r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal strPath)
        '// Remove the strings padded with  chr(0)'s
        GetSpecialfolder = Left(strPath, InStr(strPath, Chr(0)) - 1)
        Exit Function
    End If
    GetSpecialfolder = ""
End Function
You could use scripting for this BUt I prefer API as you can get a lot more of these spec folders.
__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 05:08 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.