vba 瀏覽文件夾對(duì)話框調(diào)用的幾種方法
來源:易賢網(wǎng) 閱讀:1344 次 日期:2016-06-29 08:51:26
溫馨提示:易賢網(wǎng)小編為您整理了“vba 瀏覽文件夾對(duì)話框調(diào)用的幾種方法”,方便廣大網(wǎng)友查閱!

1、使用api方法

代碼如下:

'【類型聲明】

private type browseinfo

hwndowner as long

pidlroot as long

pszdisplayname as long

lpsztitle as long

ulflags as long

lpfncallback as long

lparam as long

iimage as long

end type

'【api聲明】

private declare function shgetpathfromidlist lib shell32.dll _

alias shgetpathfromidlista (byval pidl as long, _

byval pszpath as string) as long

private declare function shbrowseforfolder lib shell32.dll _

alias shbrowseforfoldera (lpbrowseinfo as browseinfo) as long

private declare function lstrcat lib kernel32 _

alias lstrcata (byval lpstring1 as string, _

byval lpstring2 as string) as long

private declare function oleinitialize lib ole32.dll _

(lp as any) as long

private declare sub oleuninitialize lib ole32 ()

private const bif_usenewui = &h40

private const max_path = 260

'【自定義函數(shù)】

public function getfolder_api(stitle as string, optional vflags as variant) as string

dim lpidlist as long

dim sbuffer as string

dim binfo as browseinfo

if ismissing(vflags) then vflags = bif_usenewui

call oleinitialize(byval 0&)

with binfo

.lpsztitle = lstrcat(stitle, )

.ulflags = vflags

end with

lpidlist = shbrowseforfolder(binfo)

if (lpidlist) then

sbuffer = space(max_path)

shgetpathfromidlist lpidlist, sbuffer

sbuffer = left(sbuffer, instr(sbuffer, vbnullchar) - 1)

if sbuffer <> then getfolder_api = sbuffer

end if

call oleuninitialize

end function

'【使用方法】

sub test()

msgbox getfolder_api(選擇文件夾)

end sub

2、使用shell.application方法

代碼如下:

sub getfloder_shell()

set objshell = createobject(shell.application)

set objfolder = objshell.browseforfolder(0, 選擇文件夾, 0, 0)

if not objfolder is nothing then

msgbox objfolder.self.path

end if

set objfolder = nothing

set objshell = nothing

end sub

3、使用filedialog方法

代碼如下:

sub getfloder_filedialog()

dim fd as filedialog

set fd = application.filedialog(msofiledialogfolderpicker)

if fd.show = -1 then msgbox fd.selecteditems(1)

set fd = nothing

end sub

以上方法在winxp+office2003中測(cè)試通過

更多信息請(qǐng)查看腳本欄目
上一篇:dom樣式編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:vba 瀏覽文件夾對(duì)話框調(diào)用的幾種方法
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)