从fDialog获取目录的全名 [英] Getting the full name of the directory from fDialog

查看:90
本文介绍了从fDialog获取目录的全名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有以下代码.

Hi,

I have the following code.

Dim fDialog As Office.FileDialog
   Dim varFile As Variant
   Dim Path As String
   ' Set up the File Dialog.
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
   With fDialog
      
       fDialog.AllowMultiSelect = False       
      fDialog.Title = "Please Select An Excel Sheet"
      Clear out the current filters, and add our own.
      fDialog.Filters.Clear
      fDialog.Filters.Add "Excel Sheets 2003", "*.xls"
      fDialog.Filters.Add "Excel Sheets 2007", "*.xlsx"
      '.Filters.Add "All Files", "*.*"
      ' Show the dialog box. If the .Show method returns True, the
      ' user picked at least one file. If the .Show method returns
      ' False, the user clicked Cancel.
      If fDialog.Show = True Then
       Path = fDialog.InitialFileName
      'Importing the Data From Excel Sheet to access database



Path = fDialog.InitialFileName:在此语句中,路径一直到包含所选路径的最后一个文件夹为止,并且我想获取包括文件名在内的完整路径.



Path = fDialog.InitialFileName : In this statement the path comes until the last folder that contains the selected path and I want to get the full path including the file name.

How can I do that?

推荐答案

您最近是否发布了类似的问题吗?

我认为InitialFileName 不会一直按预期工作.您需要使用FileDialog.SelectedItems.对于您的情况,因为它将是单个文件名,所以您只需要访问该集合中的第一项即可.
Didn''t you post a similar question recently?

I don''t think InitialFileName will work as expected all the time. You need to use FileDialog.SelectedItems. In your case since it will be a single filename, you just need to access the first item in that collection.


这篇关于从fDialog获取目录的全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆