Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:
Microsoft Certified Partners -
https://partner.microsoft.com/global/30000104Microsoft Advisory Services -
http://support.microsoft.com/gp/advisoryserviceFor more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS
In Excel, you can create a macro to return the path to either the Windows or Windows\System directory by using the
Declare functions to access built-in functions in Windows 3.1, Windows 95, Windows 98, Windows Millennium Edition (Me), Windows NT 3.51 and 4.0, and Windows 2000. The following macros use the
GetWindowsDirectory and
GetSystemDirectory function calls to retrieve the directory information that you want.
Sample Macro
'The following two declare statements need to be entered each on a single
'line in the module sheet.
Declare Function GetSystemDirectory Lib "kernel32" Alias _
"GetSystemDirectoryA" (ByVal lpBuffer As _
String, ByVal nSize As Long) As Long
Declare Function GetWindowsDirectory Lib "kernel32" Alias _
"GetWindowsDirectoryA" (ByVal lpBuffer As _
String, ByVal nSize As Long) As Long
Sub Get_Windows_Directory()
'sets the buffer length for both variables to 144
Dim Win_Dir As String * 144
Dim Sys_Dir As String * 144
y = GetWindowsDirectory(Win_Dir, 144)
'returns the \Windows directory
wd = Left(Win_Dir, y)
'Displays the windows directory in a Message box
MsgBox wd
'Returns the Windows\System directory
x = GetSystemDirectory(Sys_Dir, 144)
sd = Left(Sys_Dir, x)
'Displays the \Windows\System directory in a Message box
MsgBox sd
End Sub