标题: 用VBA代码能清空U盘中的内容吗? [打印本页] 作者: OKK 时间: 2009-1-9 00:44 标题: 用VBA代码能清空U盘中的内容吗? 向高手请教用VBA代码能清空U盘中的内容吗?作者: Grant 时间: 2009-1-9 01:37
'格式化磁盘(危险)
'函数:FormatDisk
'参数iskName 磁盘名称,WinHwnd调用本函数的窗口句柄.
'返回值:无
'说明:
Public Function FormatDisk(DiskName As String, Optional WinHwnd As Long = 0)
Dim sFor As String
Dim sTemp As String
sFor = String(255, " ")
GetWindowsDirectory sFor, 255
sTemp = Left$(sFor, InStr(sFor, Chr$(0)) - 1) + "\rundll32.exe" _
+ Chr(0)
ShellExecute WinHwnd, vbNullString, sTemp, _
"Shell32.dll,SHFormatDrive" + Chr$(0), DiskName + Chr$(0), _
SW_SHOW
End Function作者: Grant 时间: 2009-1-9 01:38
有一定危险性,建议先备份资料作者: Grant 时间: 2009-1-9 01:38
发多一个检测移动盘的
Option Compare Database
Option Explicit
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lPBuffer As String) As Long
Private Sub Command0_Click()
Dim rtn As String, a, b$(), i%, u As Boolean
Dim AllDrives As String
AllDrives = Space$(64) '设置缓冲
rtn = GetLogicalDriveStrings(Len(AllDrives), AllDrives) '调用函数得到包含所有驱动器的字符串
AllDrives = Left(AllDrives, rtn)
a = Split(Trim(AllDrives), Chr(0))
ReDim b(UBound(a))
u = False
For i = 0 To UBound(a) - 1
b(i) = GetDriveType(a(i))
If b(i) < 2 Or b(i) > 6 Then b(i) = 1
b(i) = Choose(Val(b(i)), "未知类型", "移动盘", "硬盘", "映射盘", "光驱", "内存盘")
If b(i) = "移动盘" Then u = True
Next
Text1 = ""
Text1 = IIf(u, "发现有移动盘!", "未发现移动盘!") & vbCrLf
For i = 0 To UBound(a) - 1
Text1 = Text1 & a(i) & "---" & b(i) & vbCrLf
Next
End Sub作者: OKK 时间: 2009-1-9 12:42
真棒!谢谢您. 作者: czji 时间: 2009-4-4 23:15
检测移动盘。怎么总是提示缺少TEXT呀作者: df 时间: 2009-5-31 23:11
检测移动盘真棒作者: df 时间: 2009-6-11 00:02
检测到移动盘后 ,怎样判断一个文件是否存在并运行作者: 余方方 时间: 2011-2-12 10:10
真棒!谢谢