how to code Open Dialog to select a text file in VBA from OpenBuilding x64 (updt 8)

Hi

how to code Open Dialog to select a text file in VBA from OpenBuilding x64 (updt 8) 

in AECOSim x86 i can use 

Private Declare Function GetOpenFileNameA Lib "comdlg32.dll" 

and 

Private Declare Function GetSaveFileNameA Lib "comdlg32.dll" 

but this lib don(t work in OpenBuilding x64.

Private Function OpenDialog(OFN As OPENFILENAME) As Boolean
    ' Display the Open dialog.
    
    Dim intRes As Integer
    InitOFN OFN
    intRes = GetOpenFileNameA(OFN)
    If intRes Then
        ProcessOFN OFN
    End If
    OpenDialog = intRes
End Function

Public Function GetOpenFileName(Optional FileFilter As String, Optional FilterIndex As Long, Optional title As String = "Select a File") As String
    Dim OFN As OPENFILENAME
    With OFN
        If FileFilter <> "" Then
            .lpstrFilter = Replace(FileFilter, ",", vbNullChar) & vbNullChar
        End If
        .nFilterIndex = FilterIndex
        .lpstrTitle = title
    End With
    If OpenDialog(OFN) Then
        GetOpenFileName = OFN.lpstrFile
    End If
End Function

Private Function GetSaveAsFileName(InitialFileName As String, Optional FileFilter As String, Optional FilterIndex As Long, Optional title As String = "Select a File") As String
    Dim OFN As OPENFILENAME
    With OFN
        .lpstrFile = InitialFileName
        If FileFilter <> "" Then
            .lpstrFilter = Replace(FileFilter, ",", vbNullChar) & vbNullChar
        End If
        .nFilterIndex = FilterIndex
        .lpstrTitle = title
    End With
    If SaveDialog(OFN) Then
        GetSaveAsFileName = OFN.lpstrFile
    End If
End Function

Best regards: b.tran

Parents
  • Hello Bernard, 

    On line 13 instead of using FilterIndex as Long, use FilterIndex LongLong, so the line 13 will look like :

    Public Function GetOpenFileName(Optional FileFilter As String, Optional FilterIndex As LongLong, Optional title As String = "Select a File") As String

    the same would be with Line 27. I hope this helps you. Also please have a look at the attached wiki for more VBA related to help. 

    Regards,
    Alifur

Reply
  • Hello Bernard, 

    On line 13 instead of using FilterIndex as Long, use FilterIndex LongLong, so the line 13 will look like :

    Public Function GetOpenFileName(Optional FileFilter As String, Optional FilterIndex As LongLong, Optional title As String = "Select a File") As String

    the same would be with Line 27. I hope this helps you. Also please have a look at the attached wiki for more VBA related to help. 

    Regards,
    Alifur

Children