Private Sub Command1_Click() '首先 要从工程 部件 中选择加载 Microsoft Common Dialog Control 6.0 Me.CommonDialog1.DialogTitle = "open file" Me.CommonDialog1.Filter = "bmp files(*.bmp)|*.bmp|jpg files(*.jpg)|*.jpg|all files(*.*)|*.*" Me.CommonDialog1.ShowOpen
Dim s As String s = CommonDialog1.FileName Dim arr arr = Split(s, Chr(0)) Dim path As String Dim file1 As String Dim i As Long i = InStrRev(arr(0), "\") List1.Clear If i > 0 Then 'path = Left(arr(0), i - 1) path = IIf(Right(arr(0), 1) = "\", arr(0), arr(0) & "\") If UBound(arr) >= 1 Then For i = 1 To UBound(arr) List1.AddItem path + arr(i) Next Else List1.AddItem s End If End If End Sub
Public Function GetFile(SoftPath As String) Dim fn, mypath, myname, dirfp As String fn = SoftPath If Right(fn, 1) = "\" Then mypath = fn Else mypath = fn & "\" End If th = mypath & "*.*" myname = Dir(mypath, 0) Do While myname <> "" list1.AddItem myname myname = Dir Loop End Function
可能你想做的图片浏览的 建议Option Explicit '添加driverlistbox,dirlistbox,filelistbox,picturebox控件Private Sub Dir1_Change() File1.Path = Dir1.Path File1.Pattern = "*.bmp;*.jpg" End SubPrivate Sub Drive1_Change() Dir1.Path = Drive1.Drive End SubPrivate Sub File1_Click() Picture1.Picture = LoadPicture(File1.Path + "\" + File1.FileName) End Sub
Private Sub Command1_Click() Dim fs Set fs = CreateObject("scripting.filesystemobject") Dim f, f1 Set f = fs.getfolder("c:\bmp") For Each f1 In f.Files List1.AddItem f1.Name Next End Sub
'首先 要从工程 部件 中选择加载 Microsoft Common Dialog Control 6.0
Me.CommonDialog1.DialogTitle = "open file"
Me.CommonDialog1.Filter = "bmp files(*.bmp)|*.bmp|jpg files(*.jpg)|*.jpg|all files(*.*)|*.*"
Me.CommonDialog1.ShowOpen
Dim s As String
s = CommonDialog1.FileName
Dim arr
arr = Split(s, Chr(0))
Dim path As String
Dim file1 As String
Dim i As Long
i = InStrRev(arr(0), "\")
List1.Clear
If i > 0 Then
'path = Left(arr(0), i - 1)
path = IIf(Right(arr(0), 1) = "\", arr(0), arr(0) & "\")
If UBound(arr) >= 1 Then
For i = 1 To UBound(arr)
List1.AddItem path + arr(i)
Next
Else
List1.AddItem s
End If
End If
End Sub
Dim fn, mypath, myname, dirfp As String
fn = SoftPath
If Right(fn, 1) = "\" Then
mypath = fn
Else
mypath = fn & "\"
End If
th = mypath & "*.*"
myname = Dir(mypath, 0)
Do While myname <> ""
list1.AddItem myname
myname = Dir
Loop
End Function
楼主的意思呢?
也可以使用fso对象。
建议Option Explicit
'添加driverlistbox,dirlistbox,filelistbox,picturebox控件Private Sub Dir1_Change()
File1.Path = Dir1.Path
File1.Pattern = "*.bmp;*.jpg"
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End SubPrivate Sub File1_Click()
Picture1.Picture = LoadPicture(File1.Path + "\" + File1.FileName)
End Sub
IMAGE.PICTURE=LOADPICTURE(FILENAME) 'FILENAME包含路径和文件名
2.放如ListBox中谢谢。
Dim fs
Set fs = CreateObject("scripting.filesystemobject")
Dim f, f1
Set f = fs.getfolder("c:\bmp")
For Each f1 In f.Files
List1.AddItem f1.Name
Next
End Sub