1,488
社区成员
发帖
与我相关
我的任务
分享'添加.驱动器列表(DriveListBox),目录列表(DirListBox),文件列表(FileBox)和text1各一个
Dim ex As Object
Dim wb As Object
Dim sh As Object
Dim strFileA As String
Private Sub Command1_Click()
Dim i As Integer
Set ex = CreateObject("Excel.Application")
For i = 0 To File1.ListCount - 1
Set wb = ex.Workbooks.Open(File1.Path & "\" & File1.List(i)) '打开你文件里所有文件
Set sh = wb.Sheets(1) '打开工作表1
'Text2.Text = Text1.Text & File1.List(i) & vbCrLf '这行可以得到文件名.不过没必要,因为Filebox里已经有了
strFileA = sh.cells(1, 1) '提取所有文件的第一行第一列数据
Text1.Text = Text1.Text & strFileA & vbCrLf ' 结果
ex.Quit
Next i
Set ex = Nothing
Set wb = Nothing
Set sh = Nothing
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Form_Load()
File1.Pattern = "*.CSV" '设置你的文件类型
End Sub