我正在尝试根据当前文件夹中存在的文件数创建工作表。这是我当前的文件夹:
Folder
CalculationSheet.xls
Data1.xls
Data2.xls
Data3.xls
所以我将使用计数搜索“/*.xls
”。
我需要在CalculationSheet.xls
中创建工作表,因为我不熟悉宏。请帮帮我。
答案 0 :(得分:0)
使用类似这样的代码:
Sub GetDataFiles()
Dim strFolder As String
Dim fso As Object
Dim fileTemp As Object
Dim ws As Worksheet
' Open library of Microsoft Scripting Runtime
Set fso = CreateObject("Scripting.FileSystemObject")
strFolder = ActiveWorkbook.Path
If (fso.FolderExists(strFolder)) Then
' Check All files in the folder
For Each fileTemp In fso.GetFolder(strFolder).Files
If fileTemp.Name Like "Data*.xls" Then
Set ws = ActiveWorkbook.Sheets.Add
ws.Name = fileTemp.Name
End If
Next
End If
End Sub