매크로 | Posted by lamie 2008. 9. 25. 18:14

폴더 여는 매크로

Public Type BROWSEINFO '사용자 정의
    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 Type

'32비트 API함수 선언
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

Sub dhTest()
    Dim strMsg As String
    Dim strT As String
    strMsg = "설치하려는 폴더를 선택하세요!"
     strT = getdirectory(strMsg)
     MsgBox strT
End Sub

Function getdirectory(Optional strMsg) As String
    Dim bInfo As BROWSEINFO
    Dim path As String
    Dim r As Long, x As Long, pos As Integer

   bInfo.pidlRoot = 0&


    If IsMissing(strMsg) Then
        bInfo.lpszTitle = "폴더를 선택하세요"
    Else
        bInfo.lpszTitle = strMsg
    End If
    
    bInfo.ulFlags = &H1

ChDir ThisWorkbook.path ' & "Temp"
    x = SHBrowseForFolder(bInfo)
'    x = SHBrowseForFolder()
    
    path = Space$(512)
    r = SHGetPathFromIDList(ByVal x, ByVal path)
    If r Then
        pos = InStr(path, Chr$(0))
        getdirectory = Left(path, pos - 1)
    Else
        getdirectory = ""
    End If
End Function

'매크로' 카테고리의 다른 글

filesearch 대용  (0) 2008.10.05
사진 자동입력하는 매크로 - manual/auto  (0) 2008.09.25
화일 이름 바꾸기 매크로  (1) 2008.09.22
macro 설명  (0) 2008.09.03
엑셀 함수 목록  (0) 2008.09.02