excel 宏设计
来源:百度知道 编辑:UC知道 时间:2024/07/07 08:54:09
录制一个宏,略作修改即可。
或用如下VBA程序:
Private Sub CommandButton1_Click()
Dim TempLen As Byte
Dim TempCount As Integer
Dim strTempPath As String, ViceName As String
Dim fFile As FileSearch
Dim TempMsgBox As VbMsgBoxResult
Set fFile = Application.FileSearch
With fFile
.LookIn = "E:\多个工作簿"
.Filename = "*.xls"
If .Execute > 0 Then
TempMsgBox = MsgBox("共有" & .FoundFiles.Count & "个文件将被汇总", vbOKCancel, "记数")
If (TempMsgBox = vbCancel) Then
End
End If
TempCount = 1
Do
strTempPath = .FoundFiles(TempCount)
Debug.Print strTempPath
TempLen = Len(strTempPath)
ViceName = Mid(strTempPath, Len(fFile.LookIn) + 2, TempLen - Len(fFile.LookIn) - 1)