本人是新手,之前没有做过VB方面的开发.现在有一VBA程序,大致要求实现功能如下:
1.按浏览按钮,从一个文件浏览对话框读取一二进制文件中数据,按顺序填入EXCEL的单元格中;
2.编辑单元格中数据后,按保存按钮,可保存到原文件中,保存为二进制数据.或按另存为按钮,可指定文件出力路径,保存为二进制数据.本人看了一点帮助文档,在浏览和保存文件对话框有困难.
希望高人指点!

解决方案 »

  1.   

    在VBA里,没有通用对话框,你可以用下面的代码实现你想要的效果:'声明Private Type BrowseInfo hWndOwner As Long pIDLRoot As Long pszDisplayName As Long lpszTitle As Long ulFlags As Long lpfnCallback As Long lParam As Long iImage As Long End Type Private Const BIF_RETURNONLYFSDIRS = 1 Private Const MAX_PATH = 260 Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long) Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long 
     '代码 Public Function BrowseForFolder(hWndOwner As Long, sPrompt As String) As String Dim iNull As Integer Dim lpIDList As Long Dim lResult As Long Dim sPath As String Dim udtBI As BrowseInfo With udtBI .hWndOwner = hWndOwner .lpszTitle = lstrcat(sPrompt, "") .ulFlags = BIF_RETURNONLYFSDIRS End With lpIDList = SHBrowseForFolder(udtBI) If lpIDList Then sPath = String$(MAX_PATH, 0) lResult = SHGetPathFromIDList(lpIDList, sPath) Call CoTaskMemFree(lpIDList) iNull = InStr(sPath, vbNullChar) If iNull Then sPath = Left$(sPath, iNull - 1) End If End If BrowseForFolder = sPath End Function  
    '用法 sDirectoryName = BrowseForFolder(Me.hWnd, "请选择目录")
      

  2.   

    当我改成0后,可以使用.
    但这个对话框跟我需要的还差一点,因为我需要能有打开文件对话框那种效果,faysky2()你给的只是指定路径,并没有能精确地指定某一文件的功能.
      

  3.   

    哦,那用下面的代码:Option ExplicitPrivate Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As LongPrivate 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 TypeSub main()
        Dim OpenFile As OPENFILENAME
        Dim lReturn As Long
        Dim sFilter As String
        OpenFile.lStructSize = Len(OpenFile)
        
        sFilter = "Excel Files (*.xls)" & Chr(0) & "*.xls" & Chr(0)
        OpenFile.lpstrFilter = sFilter
        OpenFile.nFilterIndex = 1
        OpenFile.lpstrFile = String(257, 0)
        OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
        OpenFile.lpstrFileTitle = OpenFile.lpstrFile
        OpenFile.nMaxFileTitle = OpenFile.nMaxFile
        OpenFile.lpstrInitialDir = "C:\"
        OpenFile.lpstrTitle = "Use the Comdlg API not the OCX"
        OpenFile.flags = 0
        OpenFile.lpstrFile = "123.txt" '--->指定文件名
        lReturn = GetOpenFileName(OpenFile)
        If lReturn = 0 Then
            MsgBox "The User pressed the Cancel Button"
        Else
            MsgBox "The user Chose " & Trim(OpenFile.lpstrFile)
        End If
    End Sub
      

  4.   

    非常感谢,这个可以使用.
    想不到VB里也要用到WINDOWS API.保存对话框怎么做呢?是不是用GetOpenFileName相似来做?