设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 633|回复: 3
打印 上一主题 下一主题

[其它] [求助]导出目录

[复制链接]
跳转到指定楼层
1#
发表于 2005-2-28 21:29:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "ExportEmployee", "C:\Worksheet.xls", True

请问,"C:\Worksheet.xls"能否是一个变量,在用户导出数据时,会有一个象windows里一样,可以选择目录的一个窗口?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2005-2-28 22:27:00 | 只看该作者
Here it is:Private Sub Command178_Click()

Dim Sfn As String

Dim StrFilter As String

Dim lngFlags As Long



On Error GoTo Err_Command178_Click

    StrFilter = ahtAddFilterItem(StrFilter, "Excel Files(*.xls)", "*.xls")

   

    Sfn = ahtCommonFileOpenSave(InitialDir:="C:\", _

        Filter:=StrFilter, FilterIndex:=3, Flags:=lngFlags, _

        DialogTitle:="输出数据", hwnd:=Application.hWndAccessApp, OpenFile:=False)If Len(Trim(Sfn)) = 0 Then Exit SubDoCmd.OutputTo acOutputQuery, "Your table / query", acFormatXLS, Sfn, TrueExit_Command178_Click:

    Exit SubErr_Command178_Click:

    MsgBox Err.Description

    Resume Exit_Command178_Click

End Sub
3#
发表于 2005-2-28 22:31:00 | 只看该作者
Sorry!仲有一个模块,需要COPY到你的模块中,说实话,这方法不太好。

Option Compare Database

Public Sfn As String

Type tagOPENFILENAME

    lStructSize As Long

    hwndOwner As Long

    hInstance As Long

    StrFilter As String

    strCustomFilter As String

    nMaxCustFilter As Long

    nFilterIndex As Long

    strFile As String

    nMaxFile As Long

    strFileTitle As String

    nMaxFileTitle As Long

    strInitialDir As String

    strTitle As String

    Flags As Long

    nFileOffset As Integer

    nFileExtension As Integer

    strDefExt As String

    lCustData As Long

    lpfnHook As Long

    lpTemplateName As String

End TypeDeclare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _

    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As BooleanDeclare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _

    Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean

Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As LongGlobal Const ahtOFN_READONLY = &H1

Global Const ahtOFN_OVERWRITEPROMPT = &H2

Global Const ahtOFN_HIDEREADONLY = &H4

Global Const ahtOFN_NOCHANGEDIR = &H8

Global Const ahtOFN_SHOWHELP = &H10

Global Const ahtOFN_NOVALIDATE = &H100

Global Const ahtOFN_ALLOWMULTISELECT = &H200

Global Const ahtOFN_EXTENSIONDIFFERENT = &H400

Global Const ahtOFN_PATHMUSTEXIST = &H800

Global Const ahtOFN_FILEMUSTEXIST = &H1000

Global Const ahtOFN_CREATEPROMPT = &H2000

Global Const ahtOFN_SHAREAWARE = &H4000

Global Const ahtOFN_NOREADONLYRETURN = &H8000

Global Const ahtOFN_NOTESTFILECREATE = &H10000

Global Const ahtOFN_NONETWORKBUTTON = &H20000

Global Const ahtOFN_NOLONGNAMES = &H40000

Global Const ahtOFN_EXPLORER = &H80000

Global Const ahtOFN_NODEREFERENCELINKS = &H100000

Global Const ahtOFN_LONGNAMES = &H200000Function ahtCommonFileOpenSave( _

            Optional ByRef Flags As Variant, _

            Optional ByVal InitialDir As Variant, _

            Optional ByVal Filter As Variant, _

            Optional ByVal FilterIndex As Variant, _

            Optional ByVal DefaultExt As Variant, _

            Optional ByVal fileName As Variant, _

            Optional ByVal DialogTitle As Variant, _

            Optional ByVal hwnd As Variant, _

            Optional ByVal OpenFile As Variant) As VariantDim OFN As tagOPENFILENAME

Dim strFileName As String

Dim strFileTitle As String

Dim fResult As Boolean

  

    If IsMissing(InitialDir) Then InitialDir = CurDir

    If IsMissing(Filter) Then Filter = ""

    If IsMissing(FilterIndex) Then FilterIndex = 1

    If IsMissing(Flags) Then Flags = 0&

    If IsMissing(DefaultExt) Then DefaultExt = ""

    If IsMissing(fileName) Then fileName = ""

    If IsMissing(DialogTitle) Then DialogTitle = ""

    If IsMissing(hwnd) Then hwnd = Application.hWndAccessApp

    If IsMissing(OpenFile) Then OpenFile = True



    strFileName = Left(fileName & String(256, 0), 256)

    strFileTitle = String(256, 0)    With OFN

        .lStructSize = Len(OFN)

        .hwndOwner = hwnd

        .StrFilter = Filter

        .nFilterIndex = FilterIndex

        .strFile = strFileName

        .nMaxFile = Len(strFileName)

        .strFileTitle = strFileTitle

        .nMaxFileTitle = Len(strFileTitle)

        .strTitle = DialogTitle

        .Flags = Flags

        .strDefExt = DefaultExt

        .strInitialDir = InitialDir

   

        .hInstance = 0

      

        .lpfnHook = 0

   

        .strCustomFilter = String(255, 0)

        .nMaxCustFilter = 255

    End With

  

    If OpenFile Then

        fResult = aht_apiGetOpenFileName(OFN)

    Else

        fResult = aht_apiGetSaveFileName(OFN)

    End If  

    If fResult Then

        

        If Not IsMissing(Flags) Then Flags = OFN.Flags

        ahtCommonFileOpenSave = TrimNull(OFN.strFile)

    Else

        ahtCommonFileOpenSave = vbNullString

    End If

End FunctionFunction ahtAddFilterItem(StrFilter As String, _

    st
4#
 楼主| 发表于 2005-3-1 01:08:00 | 只看该作者
我只用了 DoCmd.OutputTo acOutputQuery, "Your table / query", acFormatXLS, Sfn, True,而且将sfn留白,好了,成功了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-14 14:27 , Processed in 0.089794 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表