Office家园为您提供office2003,office2007下载和一些免费的Office教程
 
您现在的位置: 首页 > Excel VBA >

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

office家园    2008-09-24

  进行文件操作时,经常要用 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



Copyright (C) 1999-2008 www.8c8n.com, All Rights Reserved 版权所有 office家园
Powered by office家园 Directx 10 希望您多提宝贵建议