Results 1 to 4 of 4

Thread: How can vb6 get the file format selected in openfilenameA lib "comdlg32.dll"?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,180

    How can vb6 get the file format selected in openfilenameA lib "comdlg32.dll"?

    I WAN'T TO SAVE FILE(NOT open file)
    How can vb6 get the file format selected in the pop-up file dialog box by calling get openfilenameA lib "comdlg32.dll"?

    IT'S BY AI,ERR:
    Code:
    Private Declare Function GetOpenFileName Lib "comdlg32.dll" (ByVal lpofn As OPENFILENAME) As Long
    Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenFilename As OPENFILENAME) As Long
    
    Private Type OPENFILENAME
        lStructSize As Long
        hwndOwner As Long
        hInstance As Long
        lpstrFilter As String
        lpstrCustomFilter As String
        nFilterIndex As Long
        nMaxFile As Long
        lpstrFile As String
        nFileOffset As Long
        nFileExtension As Long
        lpstrInitialDir As String
        lpstrTitle As String
        Flags As Long
        lpstrDefExt As String
        lPOS as Long
    End Type
    
    Private Sub OpenFileDialog()
        Dim ofn As OPENFILENAME
        Dim FileName As String
        
        ' ???????
        ofn.lStructSize = SizeOf(ofn)
        ofn.hwndOwner = Me.hWnd
        ofn.lpstrFilter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|..."
        ofn.lpstrFile = FileName
        ofn.nMaxFile = Len(FileName) * 2
        ofn.Flags = OFN_FILEMUSTEXIST Or OFN_PATHMUSTEXIST Or OFN_HIDEREADONLY
        
        ' ????
        If GetOpenFileName(ofn) Then
            ' ?????????
            MsgBox "Selected file: " & FileName
            ' ?????????????????.txt, .docx, ??
            Dim fileExt As String
            Dim fileDir As String
            fileDir = Left(FileName, InStrRev(FileName, "\") - 1)
            fileExt = Right(FileName, InStrRev(FileName, ".") - 1)
            MsgBox "File format: " & fileExt
        Else
            MsgBox "Error opening file"
        End If
    End Sub
    Last edited by xiaoyao; Aug 2nd, 2024 at 12:25 AM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,180

    Re: How can vb6 get the file format selected in openfilenameA lib "comdlg32.dll"?

    call saveas("123.xls","*.doc,*.xlsx,*.pdf")
    if i select *.doc
    how but filename is .xls,not 123.doc

  3. #3
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,141

    Re: How can vb6 get the file format selected in openfilenameA lib "comdlg32.dll"?

    Because you already specified the extension in the file title

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,180

    Re: How can vb6 get the file format selected in openfilenameA lib "comdlg32.dll"?

    Can the file format only be used when it is opened, but not when it is saved?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width