大家好,我现在写程序时遇到了点问题
    在使用commondialog控件时,我想保存文件所以方法用的是showsave
        我想固定保存文件的名称,请问用哪个属性呀(我现在试过filename和filetitle属性都不行)
    请问这个怎么设置呀!
    谢谢各位大哥大姐!

解决方案 »

  1.   

    如果是固定保存文件,就不用commondialog控件了吧!直接写文件不行吗?
      

  2.   

    With commondialog 
            .DialogTitle = "选择文件保存的路径"                
            .Filter = "所有文件|*.*"
            .FileName = 你的文件名
            .ShowSave
        End With
      

  3.   

    你应该用浏览目录就行了,文件名直接指定就行。网上很多找找个,一个api函数
      

  4.   

    什么意思??
      是以前的用commondialog 产生的filename 保存下来被以后使用吗??
      请说明白点!!
      

  5.   

    '目录浏览
    Public Type BROWSEINFOTYPE
        hOwner As Long
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As Long
        lParam As Long
        iImage As Long
    End Type
    'BROWSEINFO.ulFlags values:
    Public Const BIF_RETURNONLYFSDIRS = &H1      'Only file system directories
    Public Const BIF_DONTGOBELOWDOMAIN = &H2     'No network folders below domain level
    Public Const BIF_STATUSTEXT = &H4            'Includes status area in the dialog (for callback)
    Public Const BIF_RETURNFSANCESTORS = &H8     'Only returns file system ancestors
    Public Const BIF_EDITBOX = &H10              'Allows user to rename selection
    Public Const BIF_VALIDATE = &H20             'Insist on valid edit box result (or CANCEL)
    Public Const BIF_USENEWUI = &H40             'Version 5.0. Use the new user-interface.
                                                 'Setting this flag provides the user with
                                                 'a larger dialog box that can be resized.
                                                 'It has several new capabilities including:
                                                 'dialog box, reordering, context menus, new
                                                 'folders, drag and drop capability within
                                                 'the delete, and other context menu commands.
                                                 'To use you must call OleInitialize or
                                                 'CoInitialize before calling SHBrowseForFolder.
    Public Const BIF_BROWSEFORCOMPUTER = &H1000  'Only returns computers.
    Public Const BIF_BROWSEFORPRINTER = &H2000   'Only returns printers.
    Public Const BIF_BROWSEINCLUDEFILES = &H4000 'Browse for everything
    Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBROWSEINFOTYPE As BROWSEINFOTYPE) As Long
    Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
    Public Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Function BrowseCallbackProcStr(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lParam As Long, ByVal lpData As Long) As Long
    If uMsg = 1 Then
        Call SendMessage(hWnd, BFFM_SETSELECTIONA, True, ByVal lpData)
    End If
    End FunctionPublic Function FunctionPointer(FunctionAddress As Long) As Long
        FunctionPointer = FunctionAddress
    End FunctionPublic Function BrowseForFolder(hWnd As Long, strTitle As String, selectedPath As String) As String
        Dim Browse_for_folder   As BROWSEINFOTYPE
        Dim itemID As Long
        Dim selectedPathPointer As Long
        Dim tmpPath As String * 256
        
        If Not Right$(selectedPath, 1) <> "\" Then
            selectedPath = Left$(selectedPath, Len(selectedPath) - 1) ' 如果用户加了 "\" 则删除
        End If
        
        With Browse_for_folder
            .hOwner = hWnd ' 所有都窗口之句柄
            .lpszTitle = strTitle ' 对话框的标题
    '        .pszDisplayName = "*.frm"
            .lpfn = FunctionPointer(AddressOf BrowseCallbackProcStr) '用于设置预设文件夹的回调函数
            selectedPathPointer = LocalAlloc(LPTR, Len(selectedPath) + 1) ' 分配一个字符串内存
            CopyMemory ByVal selectedPathPointer, ByVal selectedPath, Len(selectedPath) + 1 ' 拷贝那个路径到内存
            .lParam = selectedPathPointer ' 预设的文件夹
            '.ulFlags = BIF_BROWSEINCLUDEFILES
        End With
        itemID = SHBrowseForFolder(Browse_for_folder) ' 执行API函数: BrowseForFolder
        If itemID Then
            If SHGetPathFromIDList(itemID, tmpPath) Then '取得选定的文件夹
                BrowseForFolder = Left$(tmpPath, InStr(tmpPath, vbNullChar) - 1) '去掉多余的 null 字符
            End If
            Call CoTaskMemFree(itemID) '释放内存
        End If
        Call LocalFree(selectedPathPointer) ''释放内存
    End Function
    '调用
    debug.print BrowseForFolder(Me.hWnd, "导出文件存放目录", App.Path)
    实现目录浏览功能,选定目录后,按指定的文件名保存就行。