VBA 怎么读出指定文件夹里的所有的文件名?

wuaj1980 2006-07-14 05:13:05
我在[D:\wu]放了3个[a.xls,c.xls,b.xls文件,,那么用VBA怎么去读出这三个xls的文件名?????
...全文
605 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuaj1980 2006-07-14
  • 打赏
  • 举报
回复
谢谢,,都这么热情...太感谢了...
province_ 2006-07-14
  • 打赏
  • 举报
回复
'显示插入逻辑卷根目录的文件名列表,需要在工程里引用Microsoft Scripting Runtime库。
Function ListFiles(strPath As String, ByRef list As ListBox)
Dim fso As New Scripting.FileSystemObject
Dim objFolder As Folder
Dim objFile As File

Set objFolder = fso.GetFolder(strPath)

For Each objFile In objFolder.Files
list.AddItem objFile.Name
Next
End Function
faysky2 2006-07-14
  • 打赏
  • 举报
回复
Sub getFileName()
Dim i As Long
Dim fso As Object
Dim strFolderPath As String
Dim objFolder As Object
Dim objFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
strFolderPath = "D:\wu"
Set objFolder = fso.GetFolder(strFolderPath)

If Not objFolder Is Nothing Then

For Each objFile In objFolder.Files
Debug.Print objFile.Name
Next
End If


Set objFile = Nothing
Set objFolder = Nothing
Set fso = Nothing
End Sub

2,463

社区成员

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

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