1 1 1 1 1 1 1 1 1 1 Rating 0.00 (0 Votes)

Für 32Bit und 64Bit Office Versionen

Problemstellung:

Wie ermittle ich das Windows-Verzeichnis?
Mit API

#If VBA7 Then
    'Code für 32 bit und 64 bit Office VBA 7
     #If Win64 Then
        'Code für 64-bit Office VBA 7
        Declare PtrSafe Function GetWindowsDirectory Lib "kernel32" Alias _
            "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
     #Else
        'Code für 32-bit Office VBA 7
        Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" _
            (ByVal lpBuffer As String, ByVal nSize As Long) As Long
     #End If
#Else
    'Code für VBA 6 (32 bit)
    Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" _
        (ByVal lpBuffer As String, ByVal nSize As Long) As Long
#End If

Function GetWindowsDir() As String
'*******************************************
'Name:      GetWindowsDir (Function)
'Purpose:   ermittelt das aktuelle Windowsverzeichnis
'Author:    Thomas Keßler
'Date:      Januar 28, 2003, 05:02:21
'Inputs:
'Output:
'*******************************************
Dim Ret As Long
Dim strBuffer As String, lLength As Long
  strBuffer = String$(255, 0)
  lLength = Len(strBuffer)
  Ret = GetWindowsDirectory(strBuffer, lLength)
  If Ret <> 0 Then GetWindowsDir = Left$(strBuffer, Ret)
End Function

Aufruf:

Dim x As String
x = GetWindowsDir()

Das Ergebniswäre x = "C:\WINDOWS"

 

Ähnliche Artikel