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:
Type tagOPENFILENAME 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 StringEnd 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
Hi,
dbholman said:Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32.dll"
MicroStation CONNECT Edition is 64bit program, so also VBA is 64bit. It means you cannot use 32bit dlls.
dbholman said:My other option is to convert this program to .Net
To rewrite program to NET is probably good ide in general is good idea, but it requires to rewrite the code, because new NET API is very different. It's still possible to use classic Interop API, which is quite the same as VBA API, but in my opinion it makes no sense when the code is rewritten to use old API.
But what should be possible is to use MDL functions (it was possible also in V8i) and not Windows dll files. There is mdlDialog_fileOpen function that is available both in V8i and CONNECT Edition. Maybe it's enough for what you need.
Unfortunately I have no code example, so you will have to do own research how to call this function from VBA.
Another alternative is to try to find 64bit OCX / DLL library that provides Windows dialogs access.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
good morning I apologize for my poor English, I do not know if I have understood the problem, but I enclose a macro that could solve the problemapre_file.mvba
regards
dbholman said:If anyone has another method to call an open file dialog in VBA
The Common Dialogs are Microsoft technology. Many people using platforms that incorporate 64-bit VBA, such as Microsoft Office, have asked and solved similar questions to yours. Try searching the Internet for something like 64 bit VBA file dialog. You'll receive a number of hits, such as this one.
This article shows how to use the Microsoft Common Dialogs with 64-bit MicroStation VBA.
Regards, Jon Summers LA Solutions
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
Your code is written in perfect english! I've had to throw variable names at google to try and decipher code from other non-english programmers. I'm not complaining, mind you as its not a good idea to look a gift horse in the mouth.
I'll have to plug this in to my code, but it looks great!!!! Thanks again!
Charles (Chuck) Rheault CADD Manager
MDOT State Highway Administration
Thank you.lStructSize = Len(OFN) <--- this is now .lStructSize = LenB(OFN)
I was also missing the LenB.