このコードを Excel で実行すると、Left(,) 関数が配列を想定していると表示されます。String
関数には が必要です。String
変数は として宣言されていString
ます。私はそこにオペレーターを置きまし$
たが、それでも私はがらくたをします。何が起こっているのでしょうか?
FWIW これは、SolidWorks で実行すると問題なく実行されます。
また、それを渡すユーザーフォームから呼び出されていString
ます。
#If VBA7 Then
Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal _
pszPath As String) As Long
Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long
#Else
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal _
pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long
#End If
Public Type BROWSEINFO
#If VBA7 Then
hOwner As LongPtr
pidlRoot As LongPtr
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As LongPtr
lParam As LongPtr
iImage As Long
#Else
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
#End If
End Type
Private bInfo As BROWSEINFO
Function GetDirectory(Optional Msg As String = "Select a folder.") As String
Dim path As String
Dim x As Long, pos As Integer
'dim
bInfo.pidlRoot = 0& ' Root folder = Desktop
bInfo.lpszTitle = Msg ' Dialog title
bInfo.ulFlags = &H1 ' Type of directory to return
x = SHBrowseForFolder(bInfo)
path = Space$(512)
If SHGetPathFromIDList(ByVal x, ByVal path) Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, (pos - 1))
End If
End Function