Connect VBA Open File Dialog

Hi all.

I am currently in the process of migrating my organization from V8i to Connect.  This includes the VBA that have been written over the years, most have been a non issue but there are some that used the Ken Getz code to call the cmdlg32.dll api to open and process a file, that draws out a bridge plot based on an in house geometry. I have gone through an added the needed PtrSafe to the declare function:

Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean

I have gone through and changed the declaration of tagOPENFILE name to: 

  lStructSize As Long
  hwndOwner As LongPtr
  hInstance As LongPtr
  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 LongPtr
  lpTemplateName As String
End Type

I have gotten the program to run and not crash. But it fails to open the called dialog box. I have tried every different option I came across in my searches and nothing has worked. If anyone has another method to call an open file dialog in VBA or any suggestion on getting this to work it would be appreciated.  My other option is to convert this program to .Net

  • I found the issue. It is when I initialized the tagOpenFileName. I had changed all the member names but did not change a single assignment type.

    With OFN
            .lStructSize = Len(OFN)   <--- this is now  .lStructSize = LenB(OFN)
            .hwndOwner = hwnd
            .lpstrFilter = Filter
            .nFilterIndex = FilterIndex
            .lpstrFile = strFileName
            .nMaxFile = Len(strFileName)
            .lpstrFileTitle = strFileTitle
            .nMaxFileTitle = Len(strFileTitle)
            .lpstrTitle = DialogTitle
            .flags = flags
            .lpstrDefExt = DefaultExt
            .lpstrInitialDir = InitialDir
            ' Didn't think most people would want to deal with
            ' these options.
            .hInstance = 0
            '.strCustomFilter = ""
            '.nMaxCustFilter = 0
            .lpfnHook = 0
            'New for NT 4.0
            .lpstrCustomFilter = VBA.String(255, 0)
            .nMaxCustFilter = 255
        End With

  • Thank you
    .lStructSize = Len(OFN)   <--- this is now  .lStructSize = LenB(OFN)

    I was also missing the LenB.

Reply Children
No Data