|
こんにちは
処理内容は別にして、どのブックのどのシートのどのセルを対象にした処理なのかを
明示的に書くようにして下さい。
(With ステートメント、オブジェクト変数を使用する。)
Sub test1()
Dim f As String
Dim s As String
Dim k As String
Dim i As Long
Dim w As Workbook
Dim b As Worksheet
With ThisWorkbook
f = .Path & "\*L.csv"
i = 2
s = Dir(f)
k = .Path & "\" & s
Do While s <> ""
.Worksheets("Sheet1").Cells(i, 1) = s
Set w = Workbooks.Open(k)
Set b = w.ActiveSheet
b.UsedRange.Rows("2").Copy .Worksheets("Sheet1").Cells(i, 2)
w.Close False
i = i + 1
s = Dir
k = .Path & "\" & s
Loop
End With
Set w = Nothing
Set b = Nothing
End Sub
|
|