設(shè)為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

123下一頁
返回列表 發(fā)新帖
查看: 12834|回復(fù): 29
打印 上一主題 下一主題

競賽[高8]最好和最簡潔的文件打開對話框功能

[復(fù)制鏈接]

點(diǎn)擊這里給我發(fā)消息

跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2008-3-4 14:44:04 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
80金錢
功能:使用代碼調(diào)用文件打開對話框,只可使用Access或Office本身的功能,不可使用第三方Activex控件
要求:功能符合要求,代碼最簡潔,調(diào)用最方便
獎(jiǎng)品:只取第一名 第一名增加金錢數(shù)80 增加經(jīng)驗(yàn)值10 增加魅力10
期限:10天

最佳答案

查看完整內(nèi)容

Function GetFileName(TitleText As String, Filter As String, FilterText As String, ByVal DialogType As Integer, Optional ByVal FilePath) As String '參數(shù)DialogType說明: '1.“打開”對話框 '2.“另存為”對話框(此項(xiàng)如執(zhí)行類型篩選時(shí)會(huì)出錯(cuò),所以加了出錯(cuò)處理為 Resume Next) '3.“文件選取器”對話框 '4.“文件夾選取器”對話框 '例:AA = GetFileName("打開", "*.ini;*.txt", "配置文件", 1, 3) On Error Resum ...
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 分享淘帖 訂閱訂閱
2#
發(fā)表于 2008-3-4 14:44:05 | 只看該作者
Function GetFileName(TitleText As String, Filter As String, FilterText As String, ByVal DialogType As Integer, Optional ByVal FilePath) As String
'參數(shù)DialogType說明:
'1.“打開”對話框
'2.“另存為”對話框(此項(xiàng)如執(zhí)行類型篩選時(shí)會(huì)出錯(cuò),所以加了出錯(cuò)處理為 Resume Next)
'3.“文件選取器”對話框
'4.“文件夾選取器”對話框
'例:AA = GetFileName("打開", "*.ini;*.txt", "配置文件", 1, 3)

On Error Resume Next

    Dim dlgOpen As FileDialog
    Set dlgOpen = Application.FileDialog(DialogType)
    With dlgOpen
        .Title = TitleText
        .Filters.Clear
        .Filters.Add FilterText, Filter
        .AllowMultiSelect = False
        If IsMissing(FilePath) Then
            .InitialFileName = CurrentProject.Path
        Else
            .InitialFileName = FilePath
        End If
        .Show
    End With
    If dlgOpen.SelectedItems.Count > 0 Then
        GetFileName = dlgOpen.SelectedItems(1)
    Else
        GetFileName = ""
    End If
    Set dlgOpen = Nothing

End Function
回復(fù)

使用道具 舉報(bào)

3#
發(fā)表于 2008-3-4 15:08:11 | 只看該作者
能不能引用office 11 Library
回復(fù)

使用道具 舉報(bào)

點(diǎn)擊這里給我發(fā)消息

4#
 樓主| 發(fā)表于 2008-3-4 15:18:36 | 只看該作者
也可以 是OFFICE本身的, 我知道你想取巧了
回復(fù)

使用道具 舉報(bào)

5#
發(fā)表于 2008-3-4 16:11:50 | 只看該作者
幫助里的東西總是最有效:

Dim dlgOpen As FileDialog

Set dlgOpen = Application.FileDialog( _
    DialogType:=msoFileDialogOpen)

With dlgOpen
    .AllowMultiSelect = True
    .Show
End With

For i = 1 To dlgOpen.SelectedItems.Count
sStr = sStr & dlgOpen.SelectedItems(i) & vbCrLf
Next
MsgBox sStr

[ 本帖最后由 liwen 于 2008-3-4 16:25 編輯 ]
回復(fù)

使用道具 舉報(bào)

6#
發(fā)表于 2008-3-4 16:16:43 | 只看該作者
這個(gè)當(dāng)然行,但不是最好的,應(yīng)該要寫成模塊,最起碼能自定義后綴篩選
回復(fù)

使用道具 舉報(bào)

點(diǎn)擊這里給我發(fā)消息

7#
 樓主| 發(fā)表于 2008-3-4 16:30:49 | 只看該作者
正是 至少可以指定擴(kuò)展名
回復(fù)

使用道具 舉報(bào)

8#
發(fā)表于 2008-3-4 16:33:53 | 只看該作者
Sub FilesSelect()
Dim dlgOpen As FileDialog

Set dlgOpen = Application.FileDialog( _
    DialogType:=msoFileDialogOpen)

With dlgOpen
    .AllowMultiSelect = True
    .Filters.Add "AIS文件", "*.ais", 1
    .Filters.Add "圖象", "*.gif; *.jpg; *.jpeg; *.bmp", 1
    .Show
End With
For i = 1 To dlgOpen.SelectedItems.Count
sStr = sStr & dlgOpen.SelectedItems(i) & vbCrLf
Next
MsgBox sStr

Set dlgOpen = Nothing

End Sub

還是來源于幫助

[ 本帖最后由 liwen 于 2008-3-4 16:36 編輯 ]
回復(fù)

使用道具 舉報(bào)

9#
發(fā)表于 2008-3-4 16:42:23 | 只看該作者
對話框也可支持多選的
回復(fù)

使用道具 舉報(bào)

點(diǎn)擊這里給我發(fā)消息

10#
 樓主| 發(fā)表于 2008-3-4 17:07:27 | 只看該作者
不錯(cuò), 看來API 太長了,個(gè)個(gè)都不用
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號(hào)-1 )  

GMT+8, 2024-10-23 06:27 , Processed in 0.109577 second(s), 33 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表