| 
    
     |  | Private Sub CommandButton1_Click() Dim b As Integer
 Dim d
 b = 0
 On Err GoTo エラー処理
 Range("a2").Select
 If TextBox1.Value = "" Then
 MsgBox "入力されていません"
 Else
 Range("a2:a60000").Value = ""
 Range("a2").Select
 If Len(TextBox1.Value) < 4 Then
 d = MsgBox("桁数が少ないですがこのまま実行してよろしいですか?", vbQuestion + vbOKCancel)
 If d = vbCancel Then
 Else
 With Application.FileSearch
 .NewSearch
 .LookIn = "D:\共有\給水台帳(マスター)"
 .SearchSubFolders = True
 .Filename = TextBox1.Value
 .FileType = msoFileTypeAllFiles
 If .Execute() > 0 Then
 If .Execute() > 10000 Then
 d = MsgBox("検索結果が10000件を超えますが表示してもよろしいですか? & chr(13) & はい = 全件表示 & chr(13) & いいえ = 10000件だけ表示する & chr(13) & キャンセル = 表示しない", vbQuestion + vbYesNoCancel)
 If d = vbCancel Then
 ElseIf d = vbOK Then
 MsgBox .FoundFiles.Count & " 個のファイルが見つかりました。"
 For i = 1 To .FoundFiles.Count
 ActiveCell.Value = .FoundFiles(i)
 ActiveCell.Offset(1, 0).Select
 Next i
 Beep
 UserForm1.Hide
 Application.Visible = True
 ElseIf d = vbNo Then
 For i = 1 To .FoundFiles.Count
 ActiveCell.Value = .FoundFiles(i)
 ActiveCell.Offset(1, 0).Select
 Next i
 End If
 Else
 For i = 1 To .FoundFiles.Count
 ActiveCell.Value = .FoundFiles(i)
 ActiveCell.Offset(1, 0).Select
 Next i
 End If
 Else
 MsgBox "検索条件を満たすファイルはありません。"
 End If
 End With
 End If
 Else
 With Application.FileSearch
 .NewSearch
 .LookIn = "D:\共有\給水台帳(マスター)"
 .SearchSubFolders = True
 .Filename = TextBox1.Value
 .FileType = msoFileTypeAllFiles
 If .Execute() > 0 Then
 MsgBox .FoundFiles.Count & " 個のファイルが見つかりました。"
 If .Execute() > 10000 Then
 c = MsgBox("10000件を超えますが、表示してもよろしいですか?", vbQuestion + vbYesNo)
 If c = vbYes Then
 For i = 1 To .FoundFiles.Count
 ActiveCell.Value = .FoundFiles(i)
 ActiveCell.Offset(1, 0).Select
 Next i
 Beep
 UserForm1.Hide
 Application.Visible = True
 Else
 End If
 Else
 For i = 1 To .FoundFiles.Count
 ActiveCell.Value = .FoundFiles(i)
 ActiveCell.Offset(1, 0).Select
 Next i
 Beep
 UserForm1.Hide
 Application.Visible = True
 End If
 Else
 MsgBox "検索条件を満たすファイルはありません。"
 End If
 End With
 
 End If
 End If
 Exit Sub
 エラー処理:
 Dim a
 a = MsgBox("エラーが発生しました", vbCritical + vbOKOnly, "エラー")
 End Sub
 この検索結果が一万件超えたときに”いいえ”ボタンを押したとき一万件だけエクセルに表示させるのってどうすればいいですか?
 
 |  |