I have created a VBA macro (code below) that opens the next .dgn file in the current folder. I created a custom tool and I run it from there. I created another, similar, macro that opens the "previous" drawing (not the previously opened dgn). It works, but I'm a novice at programming and I wonder if the code could be streamlined (better organized?) or if there is anything that I might have missed that will cause unexpected results. Any thoughts or comments would be appreciated. Thanks.
Sub OpenNextDgn() 'if Compile error = "User-defined type not defined" 'requires "MicroSoft Scripting Runtime" reference (Tools> References) On Error GoTo ErrorHandler ShowCommand "OpenNextDgn" Dim oFileSystem As Scripting.FileSystemObject Set oFileSystem = New Scripting.FileSystemObject Dim oFolder As Scripting.Folder Set oFolder = oFileSystem.GetFolder(ActiveDesignFile.Path) Dim DgnFiles() As String 'option base 1 Dim ArrayEmpty As Boolean ArrayEmpty = True Dim oFile As Scripting.File For Each oFile In oFolder.Files If Right(oFile.Name, 3) = "dgn" Then If ArrayEmpty Then ReDim DgnFiles(1 To 1) As String DgnFiles(1) = oFile.Name ArrayEmpty = False Else ReDim Preserve DgnFiles(1 To UBound(DgnFiles) + 1) As String DgnFiles(UBound(DgnFiles)) = oFile.Name End If End If Next oFile If UBound(DgnFiles) = 1 Then ShowPrompt "This is the only .dgn file in current folder" End ElseIf UBound(DgnFiles) > 1 Then Dim i As Integer Dim myCount As Integer For i = 1 To UBound(DgnFiles) myCount = myCount + 1 If DgnFiles(i) = ActiveDesignFile.Name Then Dim ActiveCount As Integer ActiveCount = myCount Dim NextCount As Integer NextCount = ActiveCount + 1 Exit For End If Next i If NextCount > UBound(DgnFiles) Then ShowPrompt "This is the last .dgn file in current folder" End Else myCount = 0 'reset For i = 1 To UBound(DgnFiles) myCount = myCount + 1 If myCount = NextCount Then Application.OpenDesignFile DgnFiles(i), False, msdV7ActionUpgradeToV8 CommandState.StartDefaultCommand Exit For End If Next i End If End If Exit Sub ErrorHandler: MsgBox Err.Description ShowCommand "OpenNextDgn" ShowPrompt "Error-macro failed" End Sub
Kefan Zhou said:I am browsing the Microsoft Scripting Runtime in Microstation VBA Editor, I cannot find it
Once found, it appears at the top of the list.
Several of our example VBA projects use Microsoft Scripting Runtime. For example, Export Line Data to CSV.
Regards, Jon Summers LA Solutions
Ugh,,,,, thank you!! Mine is on the tenth.
the available references are not sorted 100% alphabetically (at least for me they are not)
try looking near the top of list, mine is in the top 10 if not already selected
if you can't find it in the list I don't know, I think it should be there though
Hi JM,
As I am browsing the Microsoft Scripting Runtime in Microstation VBA Editor, I cannot find it.
However, I can find it in the vba editor in excel.
I try to manually load the scrrun.dll with the Browse, but after loading it, nothing happens in the available references.
Any suggestions?
Regards
if you read the comments at beginning of code you will see
'if Compile error = "User-defined type not defined"'requires "MicroSoft Scripting Runtime" reference (Tools> References)
you need to add the reference in VBA IDE, it won't work without it
Hi Jan,
I tried to run this code in Microstation mvba, following shows:
Any suggestion how to resolve this? I still don't quite get what "Scripting. " stands for.
Regards,
KZ
Doan Nguyen Thuc said:I want to find the input tool to list the .dgn files in the directory,
Take a look at this VBA project Next File for MicroStation.
I want to find the input tool to list the .dgn files in the directory, by scanning the selected folders, maybe at different paths, then if i press forward then it will open the next file Otherwise, it will back up, or I will choose a random file and it will open to the file. DGN, hope you help me. Thank you very much, good day
I want to find the input tool to list the .dgn files in the directory, by scanning the selected folders, maybe at different paths, then if i press forward then it will open the next file Otherwise, it will back up, or I will choose a random file and it will open to the file. DGN, hope you help me. Thank you very much, good day.