Public Sub Main() Dim Book As WorkBook Set Book = OpenedFilePath() ... End Sub Public Function OpenedFilePath() As WorkBook Dim Path As Variant Path = Application.GetOpenFilename(FileFilter:="ExcelファイルおよびCSVファイル,*.xls*;*.csv") If Path = False Then MsgBox "ファイルが選択されませんでした。" Set OpenedFilePath = Nothing Exit Function End If Dim OpenedFileName As String OpenedFileName = Dir(Path) Dim Wb As Workbook For Each Wb In Workbooks If Wb.Name = OpenedFileName Then MsgBox "選択したファイルは既に開かれています。ファイルを閉じてやり直してください。" Set OpenedFilePath = Nothing Exit Function End If Next Wb Set OpenedFilePath = Workbooks.Open(OpenedFileName, UpdateLinks:=0) End Function []