|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
小白求各位大神帮忙看看下面这段代码,FOR循环设置了变量 i , 但循环中并没有出现 i,他的作用自动指代文件夹中1到100的文件了?
Sub test1()
Dim i As Integer
Dim str As String
Dim wb As Workbook
str = Dir("d:\data\*.xls*")
For i = 1 To 100
Set wb = Workbooks.Open("d:\data\" & str)
wb.Sheets(1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = Split(wb.Name, ".")(0)
wb.Close
str = Dir
If str = "" Then
Exit For
End If
Next
End Sub
|
|