惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
J
Java Code Geeks
The GitHub Blog
The GitHub Blog
博客园_首页
U
Unit 42
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
IT之家
IT之家
G
Google Developers Blog
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
Jina AI
Jina AI
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
小众软件
小众软件
H
Help Net Security

博客园 - RayG

How to get data from Oracle DB in silverlight via WCF ? [Ray]How to use CString to create a font family - RayG [Copied] 80 VC++ tips [Copied]The GDI Coordinate Systems My Cheating Death solution in VC++ 3 given points, get the angle between two lines trouble shoot about using BindLayer in MapX with C# [原创] 计算几何常用算法(转) Trouble shooting about installation of ArcSDE 9.2 File type transform between ArcGIS and other major type - RayG [Tips] How to converting a Coverage to a Shapefile ? - RayG [Tips] How to Add New field into Shapefile attribute table in ArcGIS ? 子非鱼,安知鱼之乐? [GuanRui] My program implement on Symbian S60 (#1: File IO) - RayG My XNA HitBee small game [Ray] My GPS (卫星定位接收器) tracker program on Symbian OS Binary Tree ANSI C Implement (2) - RayG Binary Tree ANSI C Implement (1) Graph & Topology & Shortest path
[GuanRui]How to open Path browse dialog in VBA of ArcGIS ...
RayG · 2007-08-16 · via 博客园 - RayG

there are 2 ways to open a path browse dialog in VB/VBA. and there is a little diffenent between VB and VBA.
check this out ~

Way No.1 : Legacy VB
1. Add a new module in you VB project .
2. Copy & Paste the code below:

Const BIF_RETURNONLYFSDIRS = &H1Private Type SHITEMID
    cb 
As Long
    abID 
As Byte
End Type
Private Type ITEMIDLIST
    mkid 
As SHITEMID
End Type
Private 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 TypePrivate Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As StringAs Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPrivate Function GetDir(ByVal szCaption As StringAs String
    
Dim bi As BROWSEINFO, idl As ITEMIDLIST, rtn As Long, pidl As Long, pos As Long, path As String
    bi.hOwner 
= Me.hwnd        (Change Me.hwnd to Application.hwnd when you currently use VBA)
    bi.lpszTitle 
= szCaption
    bi.ulFlags 
= BIF_RETURNONLYFSDIRS
    pidl 
= SHBrowseForFolder(bi)
    path 
= Space(512)
    rtn 
= SHGetPathFromIDList(ByVal pidl, path)
    
If rtn Then pos = InStr(path$, Chr$(0)):   GetDir = Left(path, pos - 1)
End Function

3.In your form, call GetDir(Application.hWnd, "Select a path")

Way No.2 : VB for Application

1. In the VB6 IDE pull down the Project menu and select References. In the resulting dialog box scroll down to "Microsoft Shell Controls and Automation" and check the box, then click [OK]. (This is "Adding a Reference".)

2. Now (after declaring a couple variables, and finding in the VisualC++ help that the constant BIF_RETURNONLYFSDIRS is 1) this code (similar to Peter's) does in fact return JUST the folder name. For "I:\Program Files\Microsoft Visual Studio\VB98\Wizards" it returns the string "Wizards". Not too useful.

3. Now, thanks to Simon Conway-Smith's post, above, we add the code to retrieve the full (drive and) path from shlFolder.Items.Item.Path.

Here's the code, in the on-click method for a button in a test program that actually works (I just now wrote it).

Private Sub GoButton_Click()
    
Dim shlShell As Variant, shlFolder As Variant
    
Set shlShell = New Shell32.Shell
    
Set shlFolder = shlShell.BrowseForFolder(Me.hWnd, "Select a Folder"1)
    FolderLabel.Caption 
= shlFolder.Title 
    PathLabel.Caption 
= shlFolder.Items.Item.Path 
End Sub

End.