word vba 如何通过打开对话框获得打开文件名
2015-05-02 · 知道合伙人软件行家
关注
展开全部
使用GetOpenFilename即可,filenames即是文件的全路径带文件名称。
Sub ass2()
filenames = Application.GetOpenFilename("所有文件 (*.*), *.*", 0, "选定文件", , False)
MsgBox filenames
End Sub
如果仅仅只需得到文件的名称,不带路径。那么用这个:
Sub test2()
filenames = Application.GetOpenFilename("所有文件 (*.*), *.*", 0, "选定文件", , False)
If filenames <> False Then
fname = Right(filenames, Len(filenames) - InStrRev(filenames, "\"))
MsgBox fname
End If
End Sub
追问
你好,运行时,Application.GetOpenFilename提示 方法和数据成员未找到,这个怎么解决。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
word没有GetOpenFilename这个方法,需要通过excel打开
Set 连接 = CreateObject("Excel.Application")
Dim i
i = 连接.GetOpenFilename("Word文件,*.doc;*.docx;*.docm", FilterIndex:=3)
If i = False Then
'MsgBox "没有选择任何文件!"
其他 = "当前文件"
Else
其他 = i
End If
Set 连接 = CreateObject("Excel.Application")
Dim i
i = 连接.GetOpenFilename("Word文件,*.doc;*.docx;*.docm", FilterIndex:=3)
If i = False Then
'MsgBox "没有选择任何文件!"
其他 = "当前文件"
Else
其他 = i
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Sub t()
Dim ofn As OPENFILENAME
Dim rtn As String
ofn.lStructSize = Len(ofn)
ofn.lpstrFilter = "doc Files (*.doc)" & Chr(0) & "*.doc" & Chr(0)
ofn.lpstrFile = Space(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = "C:"
ofn.lpstrTitle = "打开文件"
ofn.flags = 6148
rtn = GetOpenFileName(ofn) If rtn >= 1 Then
MsgBox ofn.lpstrFile
Else
MsgBox "Cancel Was Pressed"
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼主可能说的是InlineShapes,这个是没有name属性,如果不是InlineShapes,那么只有ShapeRange了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询