Tipp 3.6 - Formatierungsdialog
Wie kann ich einen Formatierungsdialog aufrufen?
Mit dieser Funktion können Sie einen Formatierungsdialog aufrufen. Kopieren Sie einfach nachfolgenden Quellcode in die Zwischenablage und fügen Sie anschließend den Inhalt der Zwischenablage in ein neues Modul ein. Die Aufrufparameter finden Sie im Quellcode beschrieben.
Verwendete Win32-Api-Aufrufe und Typen: SHFormatDrive, GetVersionEx, GetDesktopWindow - OSVERSIONINFO
Beispiel:
Option Explicit Public Enum FORMAT_TYPES SHFD_WIN9x_FORMAT_QUICK = 0 SHFD_WIN9x_FORMAT_FULL = 1 SHFD_WIN9x_FORMAT_SYSONLY = 2 SHFD_WINNT_FORMAT_FULL = 0 SHFD_WINNT_FORMAT_QUICK = 1 SHFD_CAPACITY_DEFAULT = 0 SHFD_CAPACITY_360 = 3 '// 360KB, 5.25" SHFD_CAPACITY_720 = 5 '// 720KB, 3.5 End Enum Public Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformID As Long szCSDVersion As String * 128 End Type Public Declare Function SHFormatDrive _ Lib "shell32.dll" _ (ByVal hwndOwner As Long, _ ByVal lDrive As Long, _ ByVal lCapacity As Long, _ ByVal lFormatType As Long) As Long Public Declare Function GetVersionEx _ Lib "kernel32" Alias _ "GetVersionExA" _ (lpVersionInformation As OSVERSIONINFO) As Long Public Declare Function GetDesktopWindow _ Lib "user32" () As Long Public Function FormatDisk( _ sDrive As String, _ Optional lFormatType As Long, _ Optional lCapacity As Long = 0) As Long '// ----------------------------------------------------- '// Methode: | Ruft den Formatierungsdialog auf '// ----------------------------------------------------- '// Parameter: | sDrive = Laufwerk '// | lFormatType (opt.) = Formatierungstyp '// | lCapacity (opt.) = Kapazitätstyp '// ----------------------------------------------------- '// Rückgabe: | Long-Wert der API-Funktionsrückgabe '// ----------------------------------------------------- '// Autor: | Stefan Kulpa '// | EDV Innovation & Consulting - Dormagen '// ----------------------------------------------------- Dim lType As Long Dim lDrv As Long Dim lCap As Long Dim sDrv As String On Error Resume Next sDrive = VBA.UCase(VBA.Trim(sDrive)) sDrv = VBA.Left(sDrive, 1) lDrv = VBA.Asc(sDrv) If lDrv >= 65 And lDrv <= 90 Then _ lDrv = lDrv - 65 Else: Exit Function If IsMissing(lFormatType) Then lFormatType = _ IIf(IsWinNT, SHFD_WINNT_FORMAT_QUICK, _ SHFD_WIN9x_FORMAT_QUICK) End If If IsWinNT Then Select Case lFormatType Case SHFD_WINNT_FORMAT_FULL: lType = lFormatType Case SHFD_WINNT_FORMAT_QUICK: lType = lFormatType Case Else: Exit Function End Select Else Select Case lFormatType Case SHFD_WIN9x_FORMAT_QUICK: lType = lFormatType Case SHFD_WIN9x_FORMAT_FULL: lType = lFormatType Case SHFD_WIN9x_FORMAT_SYSONLY: lType = lFormatType Case Else: Exit Function End Select End If Select Case lCapacity Case SHFD_CAPACITY_DEFAULT: lCap = lCapacity Case SHFD_CAPACITY_360: lCap = lCapacity Case SHFD_CAPACITY_720: lCap = lCapacity Case Else: Exit Function End Select FormatDisk = SHFormatDrive(GetDesktopWindow(), _ lDrv, lCap, lType) End Function Public Property Get IsWinNT() As Boolean Const VER_PLATFORM_WIN32_NT As Long = 2 Dim uOSVer As OSVERSIONINFO uOSVer.dwOSVersionInfoSize = Len(uOSVer) GetVersionEx uOSVer IsWinNT = (uOSVer.dwPlatformID = VER_PLATFORM_WIN32_NT) End Property