dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] Function GetOpenFileName Lib "comdlg32.dll

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    4

    Resolved [RESOLVED] Function GetOpenFileName Lib "comdlg32.dll

    i think i need some help lol:
    i have a macro who Works perfectly in 32 bits... now i have a upggrade to a 64 bits program and it doesn't work... any help?

    the part that doesn't work is a call to the Function GetOpenFileName ... here is my function code:


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'API OPEN FILE
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Option Explicit
    Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OpenFileName) As LongLong
    Private 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 Type


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'FUNCION BROWSE FOR FILE
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    'Purpose : Allows the user to select a file name from a local or network directory.
    'Inputs : sInitDir The initial directory of the file dialog.
    ' sFileFilters A file filter string, with the following format:
    ' eg. "Excel Files;*.xls|Text Files;*.txt|Word Files;*.doc"
    ' [sTitle] The dialog title
    ' [lParentHwnd] The handle to the parent dialog that is calling this function.
    'Outputs : Returns the selected path and file name or a zero length string if the user pressed cancel



    Public Function BrowseForFile(sInitDir As String, Optional ByVal sFileFilters As String, Optional sTitle As String = "Open File", Optional lParentHwnd As Long) As String

    Dim tFileBrowse As OpenFileName
    Const clMaxLen As Long = 254

    tFileBrowse.lStructSize = Len(tFileBrowse)

    'Replace friendly deliminators with nulls
    sFileFilters = Replace(sFileFilters, "|", vbNullChar)
    sFileFilters = Replace(sFileFilters, ";", vbNullChar)
    If Right$(sFileFilters, 1) <> vbNullChar Then
    'Add final delimiter
    sFileFilters = sFileFilters & vbNullChar
    End If

    'Select a filter
    tFileBrowse.lpstrFilter = sFileFilters & "All Files (*.*)" & vbNullChar & "*.*" & vbNullChar

    'create a buffer for the file
    tFileBrowse.lpstrFile = String(clMaxLen, " ")
    'set the maximum length of a returned file
    tFileBrowse.nMaxFile = clMaxLen + 1

    'Create a buffer for the file title
    tFileBrowse.lpstrFileTitle = Space$(clMaxLen)
    'Set the maximum length of a returned file title
    tFileBrowse.nMaxFileTitle = clMaxLen + 1
    'Set the initial directory
    tFileBrowse.lpstrInitialDir = sInitDir
    'Set the parent handle
    tFileBrowse.hwndOwner = lParentHwnd

    'Set the title
    tFileBrowse.lpstrTitle = sTitle

    'No flags
    tFileBrowse.Flags = 0

    'Show the dialog
    If GetOpenFileName(tFileBrowse) Then
    BrowseForFile = Trim$(tFileBrowse.lpstrFile)
    If Right$(BrowseForFile, 1) = vbNullChar Then
    'Remove trailing null
    BrowseForFile = Left$(BrowseForFile, Len(BrowseForFile) - 1)
    End If
    End If
    End Function



    it doesn't do nothing when arrives to "GetOpenFileName(tFileBrowse)"

    any help?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,002

    Re: Function GetOpenFileName Lib "comdlg32.dll

    What language are you using this code in? VBA (Access, Excel), VB6, something else?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    4

    Re: Function GetOpenFileName Lib "comdlg32.dll

    vba7.1... it's a macro for a cad program named catia V5...
    my macro reads the adress and the name of a selected file and insert it several times in a determinated position

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    4

    Re: Function GetOpenFileName Lib "comdlg32.dll

    in another form i call the function:

    Private Sub CommandButton1_Click()

    On Error Resume Next

    Dim val1 As Integer
    val1 = InputBox("Nº de elementos a insertar", "aaa", "1")

    ruta0 = BrowseForFile("aaa", "part;*.CATPart|product;*.CATProduct", "Open")

    For i = 1 To val1
    Dim dirnorm(0)
    dirnorm(0) = ruta0
    products1.AddComponentsFromFiles dirnorm, "All"
    Next

    end sub

    it returns me the route and the filename of the file....

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,002

    Re: Function GetOpenFileName Lib "comdlg32.dll

    With 64 bit VBA, some of your Longs many need to be changed to LongPtr. See this page where several APIs are defined for VB7, GetOpenFileName is listed there.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    4

    Re: Function GetOpenFileName Lib "comdlg32.dll

    Tx LaVolpe... i found my solution there...

    I owe you a beer!!!!

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,002

    Re: Function GetOpenFileName Lib "comdlg32.dll

    Never a fan of virtual beer, just doesn't have the full flavor & body. Mark this thread as resolved & we'll call it even
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    New Member
    Join Date
    Mar 2019
    Posts
    1

    Re: Function GetOpenFileName Lib "comdlg32.dll

    Quote Originally Posted by paul_vete View Post
    Tx LaVolpe... i found my solution there...

    I owe you a beer!!!!
    HELLO...
    I'M using VBA in Autocad Civil3D 2019. I tried to use GetOpenFileName with no success. would you share the code that works well for you, I can't make it work...
    thanks.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width