ExcelVBA コード

Sub Sample()
    Dim OpenFileName As Variant
    OpenFileName = Application.GetOpenFilename("Microsoft Excelブック,*.xls?")
    If OpenFileName  False Then
        Workbooks.Open OpenFileName
    Else
        MsgBox "キャンセルされました"
    End If
End Sub
Sub Sample()
    Dim res As Boolean
    res = SelectFolder
    'フォルダ名取得成功時の処理
End Sub
'*******************************************************
'フォルダ選択ダイアログボックスの表示 戻り値:成功か否か
'*******************************************************
Function SelectFolder() As Boolean

    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "フォルダ選択"
        If .Show = True Then
            'フォルダ名取得後の処理
            MsgBox .SelectedItems(1) 'フルパス
            SelectFolder = True
        Else
            '処理
            SelectFolder = False
        End If
    End With
End Function
Sub ShowSheet()
    Dim ws As Worksheet
    Dim count As Integer
    count = 0
    
    For Each ws In Worksheets
        If ws.Visible  xlSheetVisible Then
          ws.Visible = xlSheetVisible
          count = count + 1
        End If
    Next
    Worksheets(1).Select
End Sub
Sub Sample()
    Dim fName As String
    fName = "test.xlsx"
    If IsOpenBook(fName) Then
        '処理
    End If
End Sub
Function IsOpenBook(ByVal bookName As String) As Boolean
    Dim res As Boolean
    Dim wb As Workbook
     
    For Each wb In Workbooks
        If wb.Name = bookName Then
            res = True
            Exit For
        End If
    Next
     
    IsOpenBook = res
End Function