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
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
Hi.
Problem comming from comdlg32.dll library not compatible with x64...
As this library seems to work only in x86, what is the x64 library to déclare Function GetOpenFileNameA ?
Best regards:
b.tran
you'd have better help in the programming forum. Also, your question is more of a general VBA question rather than Bentley specific. But here's some food for thought:
https://www.access-programmers.co.uk/forums/threads/ptrsafe-getopenfilename.298463/
Hi Bernard,
We'd be interested to know what outcome your macro is reaching?
Marc