| 特定フォルダ内のブックから複数のブックをランダムに開く |
|---|
サンプルマクロは、C:\内の複数のブックをランダムに3分の1の
確率で開きます。
Sub Sample()
'ファイルの存在するフォルダ
Const myDir As String = "C:\"
Dim myFileName As String
Dim myCnt As Long, i As Long
'開く確率 = 1 / myRndRate
Const myRndRate As Long = 3
myFileName = Dir(myDir & "*.xls")
With Application
.DisplayAlerts = False
While myFileName <> vbNullString
Randomize
If Int(Rnd * myRndRate) + 1 = 1 Then _
Workbooks.Open myDir & myFileName
myFileName = Dir()
Wend
.DisplayAlerts = True
End With
End Sub
|
| Excel97/2000 |