乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 在<em>EXCEL</em>中获取文件路径

在<em>EXCEL</em>中获取文件路径

作者:乔山办公网日期:

返回目录:excel表格制作


Sub s()
    Dim pth$
    pth = ThisWorkbook.Path
    MsgBox "本文件的路径为:" & pth
End Sub


有两个方法:
1、用INFO函数
在“文件2.XLS”中,在任意单元格中输入公式=INFO("directory")
就可以返回这个工作簿的路径
2、打开“文件2.XLS”所在的文件夹,并选中这个工作簿,从文件夹上面的地址栏中可以复制这个工作簿的路径。
'注意引用 microsoft office 10.0 (或以上) object library
'在文件对话框对中返回选择一个文件夹的路径.
Public Function ChooseFolder() As String
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(msoFileDialogFolderPicker)
With dlgOpen
If .Show = -1 Then
ChooseFolder = .SelectedItems(1)End IfEnd With
Set dlgOpen = Nothing
End Function
'--------------------------------------------------------
'在文件对话框对中,选择一个文件。
Public Function ChooseOneFile(Optional TitleStr As String
= 选择你要e799bee5baa6e4b893e5b19e337的文件, Optional TypesDec As String = 所有文件,
Optional Exten As String = *.*) As String
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
With dlgOpen
.Title = TitleStr
.Filters.Clear '清除所有的文件类型.
.Filters.Add TypesDec, Exten
.AllowMultiSelect = False '不能多选.
If .Show = -1 Then
' .AllowMultiSelect = True '多个文件
' For Each vrtSelectedItem In .SelectedItems
' MsgBox Path name: & vrtSelectedItem
' Next vrtSelectedItem
ChooseOneFile = .SelectedItems(1) '第一个文件End IfEnd With

你直接指定文件夹即可
Sub test()
On Error GoTo err_fopen
Dim fopen As FileDialog
Set fopen = Application.FileDialog(msoFileDialogFilePicker)
fopen.InitialFileName = "d:\AB\*.dxf"
fopen.Show
Range("N1") = fopen.SelectedItems(1)
Set fopen = Nothing
Exit Sub
err_fopen:
MsgBox "未选择文件"
End Sub

相关阅读

  • 在<em>EXCEL</em>中获取文件路径

  • 乔山办公网excel表格制作
  • Sub s() Dim pth$ pth = ThisWorkbook.Path MsgBox "本文件的路径为:" & pthEnd SubExcel文件,读取文件路径,在当前路径下新建一个文件夹..." src="/uploads/tu/354.jpg" style="widt
  • Excel excel下拉框如何设置多个多选

  • 乔山办公网excel表格制作
  • 1、直接插入符号:插入--文本--符号 2、插入控件:开发工具--控件--插入,有两种控件可以选择,在下拉框上点击右键——设置控件属性——使用数据-数据效性功能做列表框;复选框能工具
  • -excel 2010 时间控件,excel控件使用方法

  • 乔山办公网excel表格制作
  • 1打开EXCEL,在工具栏空白处右击,在弹出的菜单百中选择控件工具箱。2在选择控件工具箱点击如图位置度。3在弹出知的菜单中选择DTP控件。4拖动道鼠标,这个时候会产生一个DTP控件。
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网