これは Sid のものと似ていますが、単一のセルをダブルクリックしてファイル ダイアログを開くことができます。
モジュール内

Public Function getList(Optional ByVal Target As Range = Nothing) As String
Dim Dialog As FileDialog
Dim File As Integer
Dim Index As Integer
Dim List() As String
Dim Item As Integer
Dim Skip As Boolean
Set Dialog = Application.FileDialog(msoFileDialogFilePicker)
File = Dialog.Show
If File = -1 Then
' Get a list of any pre-existing files and clear the cell
If Not Target Is Nothing Then
List = Split(Target.Value, "|")
Target.Value = ""
End If
' Loop through all selected files, checking them against any pre-existing ones to prevent duplicates
For Index = 1 To Dialog.SelectedItems.Count
Skip = False
For Item = LBound(List) To UBound(List)
If List(Item) = Dialog.SelectedItems(Index) Then
Skip = True
Exit For
End If
Next Item
If Skip = False Then
If Result = "" Then
Result = Dialog.SelectedItems(Index)
Else
Result = Result & "|" & Dialog.SelectedItems(Index)
End If
End If
Next Index
' Loop through the pre-existing files and add them to the result
For Item = UBound(List) To LBound(List) Step -1
If Not List(Item) = "" Then
If Result = "" Then
Result = List(Item)
Else
Result = List(Item) & "|" & Result
End If
End If
Next Item
Set Dialog = Nothing
' Set the target output if specified
If Not Target Is Nothing Then
Target.Value = Result
End If
' Return the string result
getList = Result
End If
End Function
ワークシートのコード内

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then getList Target
End Sub
更新
getList 関数を変更しました (壊れていませんでした。より多くの機能を追加しただけです)。
- 任意のセルをダブルクリックすると、ファイル ダイアログが開きます。
- 1 つ (または複数) のファイルを選択できます
- ファイル名は「|」で結合されます。文字とターゲットセルに入れる
- 既存のファイルがセルにある場合、新しいファイルがそれらに追加されます
ただし、Enter キーを押してファイル ダイアログを開くことはサポートされていません。セルをダブルクリックする必要があります。
更新
VMO を支援するには (コメント投稿者)
ワークシート モジュールのコード:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then
If Target.Address = "$A$1" Then ' See Notes Below
Target.Value = getList(Target)
End If
End If
End Sub
ダブルクリックできるセルを制限するには、そのようなものを使用する必要があります。必要なものに変更$A$1
したり、ターゲット範囲の名前を決定する方法を見つけたりすることができます (それほど難しくありません)。
ワークシートがロックされていない場合、クリックされたセルはフォーカスを維持し、少し面倒な編集モードになります。セルをロックすると、以前のバージョンの Excel でこれが修正されました (ただし、v.2010 以降では機能しないと思います)。
モジュール (getList) 内のコードはほぼ同じままでかまいません (必須ではありませんが、複数のファイルを処理するすべてのコードを削除したい場合もあります)。1 行のコードを追加するだけです。
.......
Dim Skip As Boolean
Set Dialog = Application.FileDialog(msoFileDialogFilePicker)
Dialog.AllowMultiSelect = False ' This will restrict the dialogue to a single result
File = Dialog.Show
If File = -1 Then
......
これがお役に立てば幸いです。あなたが求めていたことを理解しました!