'アクティブブックのあるフォルダを開くマクロ Option Explicit Declare Function GetDesktopWindow Lib "user32" () As Long Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" ( _ ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long Function MyFileOpen(filename As String) As Long MyFileOpen = ShellExecute(GetDesktopWindow(), _ "Open", filename, "", CurDir(), 1) End Function 'ファイルパスからフォルダ名を取得する関数 Function GetFolderFromPath(s As String) As String Dim i As Integer Dim sep As String sep = Application.PathSeparator For i = Len(s) To 1 Step -1 If Mid$(s, i, 1) = sep Then GetFolderFromPath = Left$(s, i) Exit Function End If Next GetFolderFromPath = "" End Function 'アクティブブックのあるフォルダを開くマクロ Sub FolderOpen_ActiveWorkbook() MyFileOpen ActiveWorkbook.Path End Sub 'アクティブセル値のファイルのフォルダを開くマクロ Sub FolderOpen_ActiveCell() If TypeName(Selection) <> "Range" Then Exit Sub MyFileOpen GetFolderFromPath(ActiveCell.Value) End Sub 'アクティブセル値のファイルを開くマクロ Sub FileOpen_ActiveCell() If TypeName(Selection) <> "Range" Then Exit Sub MyFileOpen ActiveCell.Value End Sub