如何选中多个文件?

death 2005-09-07 05:28:40
用通用对话框的flags属性=cdlOFNAllowMultiselect是可以的,但是那个文件对话框也太不好看了,而且返回的多个文件名是用空格隔开的,怎么实现象类似excel那样的文件打开对话框,可以选多个文件。
...全文
1042 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jam021 2005-09-23
  • 打赏
  • 举报
回复
关注
weiweiplay 2005-09-19
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim i As Integer, title As String, FileNames As String

ComDialogFax.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNLongNames
ComDialogFax.Filter = "All Excel Files (*.xls)|*.xls|All files (*.*)|*.*"
ComDialogFax.FilterIndex = 1
ComDialogFax.InitDir = "C:\"
ComDialogFax.FileName = ""
ComDialogFax.CancelError = False
ComDialogFax.ShowOpen

i = InStrRev(ComDialogFax.FileName, "\") '
title = Left(ComDialogFax.FileName, i) ' Ŀ¼
FileNames = Mid(ComDialogFax.FileName, i + 1) ' all selectes files
Do While Len(FileNames) > 0
title = GetLeftWords(FileNames, Chr(0))
MsgBox title
Loop
End Sub

Function GetLeftWords(s As String, ByVal Ch As String) As String
Dim i As Long
i = InStr(s, Ch)
If i > 0 Then
GetLeftWords = Left(s, i - 1)
s = Mid(s, i + Len(Ch))
Else
GetLeftWords = s
s = vbNullString
End If
End Function

death 2005-09-09
  • 打赏
  • 举报
回复
真的没人知道吗?高手何在啊?
death 2005-09-08
  • 打赏
  • 举报
回复
另外,我是用的win2000,那cdlOFNExplorer 是不是就没什么用啊?
death 2005-09-08
  • 打赏
  • 举报
回复
问题是多个文件用空格格开? 如果文件本身有空格怎么办? 通用对话框这样好象比较。。。
有什么更好的方法吗?
northwolves 2005-09-07
  • 打赏
  • 举报
回复
http://blog.csdn.net/northwolves/archive/2005/08/30/468251.aspx

flags:
cdlOFNExplorer &H80000
它使用类似资源管理器的打开一个文件的对话框模板。适用于 Windows 95 和 Windows NT 4.0。

cdlOFNAllowMultiselect &H200
它指定文件名列表框允许多重选择。
运行时,通过按 SHIFT 键以及使用 UP ARROW 和 DOWN ARROW 键可选择多个文件。作完此操作后,FileName 属性就返回一个包含全部所选文件名的字符串。串中各文件名用空格隔开


Private Sub Command1_Click()
Dim i As Integer, title As String, FileNames As String
With CommonDialog1
.FileName = ""
.Filter = "All Files|*.*" '过滤器指定在对话框的文件列表框中显示的文件的类型
.Flags = &H80200 '允许多重选择。'!!!!!!!!!!!
.Action = 1
' i = InStrRev(.FileName, "\") '
' title = Left(.FileName, i) ' 目录
' FileNames = Mid(.FileName, i + 1) ' all selectes files
' End With
' FileNames = Replace(FileNames, Chr(32), vbCrLf)
' MsgBox FileNames, vbYesNo, title '显示对话框
End Sub
death 2005-09-07
  • 打赏
  • 举报
回复
有没有更简单的,象excel那样的
wangdeshui 2005-09-07
  • 打赏
  • 举报
回复
自己做一个,把某目录下你要的文件加载到列表框,再选择

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧