关于VB的Commondialog打开多个文件的问题
我在网上看到的代码:Dimsfile$,sPrivateSubCommand1_Click()OnErrorGoToerrhandlerWithCommonDialog1...
我在网上看到的代码:
Dim sfile$, s
Private Sub Command1_Click()
On Error GoTo errhandler
With CommonDialog1
.DialogTitle = "打开多个文件"
.Filter = "所有文件 (*.*)|*.*"
.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
.ShowOpen
End With
s = Split(CommonDialog1.FileName, Chr(0))
For i = 1 To UBound(s)
List1.AddItem IIf(Right(s(0), 1) = "\", s(0), s(0) & "\") & s(i)
Next i
errhandler:
If Err > 0 Then Exit SubEnd Sub
但是当我选中一个文件的时候,List1不会添加任何东西
有哪位大侠能给我一个选中一个文件时,List1也能添加东西的代码,谢谢!
这段代码已经是能调出多选文件的对话框的了,而假如我在多选文件的对话框内选择一个文件,列表内就没有添加,请问怎么办,谢谢 展开
Dim sfile$, s
Private Sub Command1_Click()
On Error GoTo errhandler
With CommonDialog1
.DialogTitle = "打开多个文件"
.Filter = "所有文件 (*.*)|*.*"
.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
.ShowOpen
End With
s = Split(CommonDialog1.FileName, Chr(0))
For i = 1 To UBound(s)
List1.AddItem IIf(Right(s(0), 1) = "\", s(0), s(0) & "\") & s(i)
Next i
errhandler:
If Err > 0 Then Exit SubEnd Sub
但是当我选中一个文件的时候,List1不会添加任何东西
有哪位大侠能给我一个选中一个文件时,List1也能添加东西的代码,谢谢!
这段代码已经是能调出多选文件的对话框的了,而假如我在多选文件的对话框内选择一个文件,列表内就没有添加,请问怎么办,谢谢 展开
展开全部
重新试试
Private Sub Form_Load()
CommonDialog1.MaxFileSize = 32767
CommonDialog1.DialogTitle = "打开多个文件"
CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer '多选
CommonDialog1.Filter = "所有文件(*.*)|*.*"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
p = Split(CommonDialog1.FileName, vbNullChar)(0)
If UBound(Split(CommonDialog1.FileName, vbNullChar)) > 0 Then
For Each s In Split(CommonDialog1.FileName, vbNullChar)
If s <> p Then
If Right(p, 1) <> "\" Then p = p & "\"
List1.AddItem p & s
End If
Next
CommonDialog1.FileName = ""
Else
List1.AddItem p
End If
End If
End Sub
Private Sub Form_Load()
CommonDialog1.MaxFileSize = 32767
CommonDialog1.DialogTitle = "打开多个文件"
CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer '多选
CommonDialog1.Filter = "所有文件(*.*)|*.*"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
p = Split(CommonDialog1.FileName, vbNullChar)(0)
If UBound(Split(CommonDialog1.FileName, vbNullChar)) > 0 Then
For Each s In Split(CommonDialog1.FileName, vbNullChar)
If s <> p Then
If Right(p, 1) <> "\" Then p = p & "\"
List1.AddItem p & s
End If
Next
CommonDialog1.FileName = ""
Else
List1.AddItem p
End If
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询