I'm currently trying to create a dialog box to return selected file names for another macro.
I've using the code from Learning Microstation VBA: The mdlDiaiog_fileOpen Function, of which I'm planning to modify for my needs.
Declare Function mdlDialog_fileOpen Lib "stdmdlbltin.dll" (ByVal fileName As String, ByVal rFileH As Long, ByVal resourceld As Long, ByVal suggestedFileName As String, ByVal filterString As String, ByVal defaultDirectory As String, ByVal titleString As String) As LongSub TestFileOpenA() Dim strFName As String Dim lngfhandle As Long Dim lngrid As Long Dim retVal As Long strFName = Space(255) retVal = mdlDialog_fileOpen(strFName, lngfhandle, lngrid, "*.dgn ", "C:\MicroStation VBA", "Open File") Select Case retVal Case 0 ' Open strFName = Left(strFName.InStr(l, strFName, Chr(O)) - 1) MsgBox "File Selected: " & vbCr & strFName Case 1 ' Cancel MsgBox "No File Selected."End Select
End Sub
Unfortunately it doesn't seem to work.
When I play this macro I get a Compile error: Argument not optional, highlighting "mdlDialog_fileOpen" inside the procedure as the problem.
I've checked to make sure the dll "stdmdlbltin.dll" is in the right directory.
I'm running Microstation V8i (SS3) on a Windows 7 OS if that helps
Not sure what else to check. Any help would be greatly appreciated.
Regards,
Josh
Hi Josh,
you missed suggestedFileName argument in the function call. There are also a couple of typos in strFName = Left... line. Corrected code is this:
Sub TestFileOpenA() Dim strFName As String Dim lngfhandle As Long Dim lngrid As Long Dim retVal As Long strFName = Space(255) retVal = mdlDialog_fileOpen(strFName, lngfhandle, lngrid, "", "*.dgn ", "C:\MicroStation VBA", "Open File") Select Case retVal Case 0 ' Open strFName = Left(strFName, InStr(1, strFName, Chr(0)) - 1) MsgBox "File Selected: " & vbCr & strFName Case 1 ' Cancel MsgBox "No File Selected." End Select End Sub
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Unknown said:Thought I'd be able to select multiple files though so don't think this will work.
Based on what fact did you think this function can be used to choose multiple files? I see no information in the mentioned book and also checking MDL API documentation, which says Displays a Dialog Box that lets the user choose a file to open, I see nothing like this.
I guess you have to call Win32 API and to use some standard Windows File Open dialog to be able to work with more files and don't rely to what MicroStation offers. I recommend to check VBA forums on StackOverflow or other webs (there are plenty of them) as it's general VBA question, not MicroStation VBA specific.
Unknown said:Thought I'd be able to select multiple files...
You need to use the Microsoft Common Dialogs, although Microsoft doesn't make it easy from VBA. However, your question is common to all implementations of VBA: search web forums that cover VBA programming for Office products using keywords VBA common dialog multiple file chooser.
Regards, Jon Summers LA Solutions