WEB开发网
开发学院软件教学办公软件Excel Excel中调用VBA选择目标文件夹 阅读

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

 2008-09-01 14:28:28 来源:WEB开发网   
核心提示:进行文件操作时,经常要用 VBA 选择目标文件夹,Excel中调用VBA选择目标文件夹,现提供实现代码: 1.FileDialog 属性Sub Sample1() With application.FileDialog(msoFileDialogFolderPicker) If .Show = True Then Ms

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

Tags:Excel 调用 VBA

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接