VB 打开TEXT中输入的目录

来源:百度知道 编辑:UC知道 时间:2024/06/05 07:42:02
dim a

Private Sub Command1_Click()
If IsNumeric(Text1.Text) Then Exit Sub
If a = "c" Or a = "d" Or a = "e" Or a = "f" Or a = "g" Or a = "h" Or a = "i" Or a = "j" Or a = "k" Or a = "l" Or a = "m" Or a = "n" Then

a = a + ":\"
Shell ("explorer.exe " & a), 1
Else
End If
End Sub

Private Sub Text1_Change()
a = Text1.Text
End Sub

我想知道哪里错了?
要打开TEXT1中输入的盘符,如输入E则打开E:\

不必要那么麻烦 一句解决。。
Private Sub Command1_Click()'只要硬盘存在的文件夹或文件都会打开
If Dir(Text1.Text) <> "" Then Shell ("explorer.exe " & Text1.Text), 1
End Sub

Private Sub Command2_Click()'只打开文件夹
If (GetAttr(Text1.Text) And vbDirectory) = vbDirectory Then Shell ("explorer.exe " & Text1.Text), 1
End Sub

哦,是初学么...
还是这么来吧,上面的实现太麻烦了,效率也低,
试一试我的代码

Private Sub Command1_Click()

Dim strTmp As String

strTmp = Text1.Text

If Not strTmp Like "[A-z]" Then Exit Sub

strTmp = strTmp & ":\"

Call Shell("explorer.exe " & strTmp, vbNormalFocus)

End Sub

Private Sub Form_Load()

With Text1
.MaxLength = 1
.Text = "c"
End With

End Sub

测试通过呀。