Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created January 31, 2012 00:10
Show Gist options
  • Save kumatti1/1707713 to your computer and use it in GitHub Desktop.
Save kumatti1/1707713 to your computer and use it in GitHub Desktop.
VBAでのIFileDialog
自作したTypeLibに参照設定
Option Explicit
Declare Sub CoTaskMemFree Lib “Ole32.dll” (ByVal pv&)
Declare Function lstrlenW& Lib “Kernel32.dll” (ByVal lpString&)
Declare Sub RtlMoveMemory Lib “Kernel32.dll” (ByVal Destination&, ByVal Source&, ByVal length&)
Sub hoge()
Dim o As IFileOpenDialog
Dim si As IShellItem
Dim tmp&, hr&, length&, s$
Set o = New FileOpenDialog
hr = o.Show(Application.Hwnd)
’ 非選択時
If hr < 0 Then Exit Sub
’ IShellItemの参照のセット
Set si = o.GetResult
’ 選択したパスを得る
si.GetDisplayName SIGDN_FILESYSPATH, VarPtr(tmp)
length = lstrlenW(tmp)
s = String$(length, 0)
RtlMoveMemory StrPtr(s), tmp, length * 2
CoTaskMemFree tmp
MsgBox s
End Sub
http://www1.axfc.net/uploader/File/so/74744
# アップローダーに置きました。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment