Office中国论坛/Access中国论坛

标题: [分享]不采用控件或调用API函数的打开对话框,文件选取框和文件夹选取框。 [打印本页]

作者: fan0217    时间: 2006-2-27 00:20
标题: [分享]不采用控件或调用API函数的打开对话框,文件选取框和文件夹选取框。
打开对话框,一般都采用控件或调用API函数,此函数虽然采用的Microsoft Office 11.0 Object Library,但没有使用常量名称做参数,所以不需要引用Microsoft Office 11.0 Object Library。

Function GetFileName(ByVal DialogType As Integer) As String
'参数DialogType说明:
'1.“打开”对话框
'3.“文件选取器”对话框
'4.“文件夹选取器”对话框
'不对dlgOpen进行声明的原因是:不需要引用Microsoft Office 11.0 Object Library
Set dlgOpen = Application.FileDialog(DialogType)
    With dlgOpen
        .AllowMultiSelect = False
        .Show
    End With
    If dlgOpen.SelectedItems.Count > 0 Then
        GetFileName = dlgOpen.SelectedItems(1)
    Else
        GetFileName = ""
    End If
Set dlgOpen = Nothing
End Function


参数2为“另存为”对话框,采用上述返回值不太合适。打开另存为对话框函数:

Function FileSaveAs()
'不对dlgOpen进行声明的原因是:不需要引用Microsoft Office 11.0 Object Library
Set dlgOpen = Application.FileDialog(2)
    With dlgOpen
        .AllowMultiSelect = False
        .Show
    End With
  Set dlgOpen = Nothing
End Function




帮助信息请参考:Application 对象的FileDialog 属性


[此贴子已经被作者于2006-2-26 16:26:12编辑过]

作者: 一点通    时间: 2006-2-27 00:26
Set dlgOpen = Application.FileDialog(DialogType)

这句出错,请修改一下

作者: fan0217    时间: 2006-2-27 00:30
没有不对啊!在几台电脑上顺利通过。都没有引用Microsoft Office 11.0 Object Library

实在不行就引用:Microsoft Office xx.x Object Library

[此贴子已经被作者于2006-2-26 16:37:01编辑过]


作者: bqwd36    时间: 2006-3-19 03:38
也是一样的问题,2000下面没法用
作者: nagee    时间: 2006-3-19 06:30
XP中的另存为也不行!
作者: 爱情插班生    时间: 2006-6-11 01:31
很好的例子,我喜欢.[em01][em01][em01]
作者: ericchina    时间: 2006-9-3 21:37
在access中没有filedialog对象。
作者: ruige056011    时间: 2006-10-2 20:40
ji几吧麻烦


作者: ruige056011    时间: 2006-10-2 20:41
在发
作者: ruige056011    时间: 2006-10-2 20:41
发啊
作者: djch    时间: 2008-6-19 22:27
学习啊学习!
作者: waltonw    时间: 2008-7-27 22:35
thks
作者: darwenli    时间: 2008-10-18 15:57
learn it first
作者: xyxj1974    时间: 2008-10-18 16:40
收到.
作者: chenlugen    时间: 2008-11-19 15:31
看看,,
作者: chenlugen    时间: 2008-11-19 15:31
下下来行
作者: dongzhaohui    时间: 2008-11-21 13:37
谢谢,真需要
作者: lirong    时间: 2008-11-21 21:04
发啊
作者: yori2007    时间: 2008-12-15 11:54
[:50]
作者: becao    时间: 2008-12-16 20:24
很好 Good
作者: becao    时间: 2008-12-16 20:24
标题: 很好 Good
很好 Good
作者: koutx    时间: 2008-12-31 14:37
看看看看
作者: ggjjss    时间: 2009-3-20 14:53
谢谢分享
作者: szyewj    时间: 2009-4-17 11:54
2000下面没法用
作者: wzh    时间: 2009-8-15 08:31
看看
作者: chaojianan    时间: 2009-9-27 09:17
看看,谢谢分享。
作者: sagemeyou    时间: 2009-11-6 16:23
谢谢分享
作者: envolepe    时间: 2011-1-24 15:58
试下试下
作者: danielofapollo    时间: 2011-4-1 12:28
学习下看看
作者: szyewj    时间: 2011-5-11 01:24
学习学习
作者: yanwei82123300    时间: 2011-5-11 08:34
谢谢分享
作者: garybian2002    时间: 2011-5-20 13:51
学习
作者: huangxiuwen    时间: 2011-5-25 16:21
学习
作者: alonet    时间: 2011-8-26 09:54
看看
作者: jakyky    时间: 2011-11-28 12:08
看看先
作者: wufeng980114    时间: 2012-9-7 21:35
学习下
作者: zxclen    时间: 2014-7-14 16:02
SEEEEEEEEEEEEEEEEEEE
作者: lshstruc    时间: 2015-6-8 23:32
看看
作者: lintina892    时间: 2015-6-29 14:18
3Q3Q3Q3Q3Q3Q3Q3Q
作者: Superleistung    时间: 2016-6-6 16:40
非常有帮助~谢谢
作者: niculas    时间: 2019-1-21 18:57
学习学习
作者: zhao__feng    时间: 2019-4-25 10:22
谢谢




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3