![]() |
|
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Join Date: Jul 2003
Location: California
Posts: 111
|
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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,738
|
Something like
Code:
Private Sub CommandButton1_Click() MsgBox "The OS is : " & OS_Version End Sub |
|
|
|
|
|
#3 |
|
Join Date: Jul 2003
Location: California
Posts: 111
|
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 |
|
|
|
|
|
#4 |
|
Join Date: Jul 2003
Location: California
Posts: 111
|
bump
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,208
|
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
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|