| 订阅 | 在线投稿
分享
 
 
 

Excel中调用VBA选择目标文件夹

来源:互联网  宽屏版  评论
2008-09-02 06:53:52

进行文件操作时,经常要用 VBA 选择目标文件夹,现提供实现代码:

1.FileDialog 属性

Sub Sample1()

With Application.FileDialog(msoFileDialogFolderPicker)

If .Show = True Then

MsgBox .SelectedItems(1)

End If

End With

End Sub

2.shell 方法

Sub Sample2()

Dim Shell, myPath

Set Shell = CreateObject("Shell.Application")

Set myPath = Shell.BrowseForFolder(&O0, "请选择文件夹", &H1 + &H10, "G:")

If Not myPath Is Nothing Then MsgBox myPath.Items.Item.Path

Set Shell = Nothing

Set myPath = Nothing

End Sub

 
进行文件操作时,经常要用 VBA 选择目标文件夹,现提供实现代码:   1.FileDialog 属性 Sub Sample1()    With Application.FileDialog(msoFileDialogFolderPicker)      If .Show = True Then        MsgBox .SelectedItems(1)      End If    End With End Sub   2.shell 方法 Sub Sample2()    Dim Shell, myPath    Set Shell = CreateObject("Shell.Application")    Set myPath = Shell.BrowseForFolder(&O0, "请选择文件夹", &H1 + &H10, "G:")    If Not myPath Is Nothing Then MsgBox myPath.Items.Item.Path    Set Shell = Nothing    Set myPath = Nothing End Sub
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有