Help needed: Data in Excel VBA from Microstation DGN Files

I3looM

New Member
Joined
Jun 22, 2010
Messages
12
Hi All
I previously had some excellent help from users with an existing VBA app that I have amended to my needs. I have it working however I've found some instances where it doesn't work and given that it is excel based I thought I'd take a chance and see if anyone can read the code and tell me why it doesn't work even though it pulls data created in another application.

What does the vba do?
The app has a user browse and select a folder which contains files with a .DGN extension, this path is added to a cell in the worksheet. Within these files exists Text Data on a title box that when printed shows the information like drawing name, scale, revisions etc... This text is a special type called a tag. A Tag's primary purpose is to store a data value and each tag has a name and a value e.g. a tag called 'Scale' might have the value 1:100. These Tags are associated to a host element which in this case is a piece of text.

How do you get this tag information from Microstation to Excel?
When the user presses the import button the VBA scans these files looking for the predefined tag names, if it finds any of these names in the files then the values of these are populated into the corresponding cells in the excel sheet. This process is repeated via enumeration until all files are scanned & data imported.

A brief explanation of Microstation DGN files
A DGN file is composed of models (at least 1 model). All files contain a Design Model - this is the location where graphical data is drawn. In my office we use a second type of Model called a Sheet Model - This where we create a virtual piece of paper and compose the pre-drawn graphical data and place a border sheet around these elements. It is within this border sheet that the tag elements reside.

Ok so you have it working, whats wrong?
The VBA works fine when I have 1 design model (required) and 1 sheet model. If I create a second design model it stops working even though none of these design models contain the tags - they always reside in the sheet model. Here's the code from the start up to the section I believe is causing the problem:

Code:
'Microstation Application
Dim oMSApp As MicroStationDGN.Application

'Microstation Related Variables
Dim myDGN As DesignFile
Dim oTagSet As TagSet
Dim oTag As TagElement
Dim oEnumerator As ElementEnumerator
Dim myString As String

'File System Related Variables
Dim myFSO As New Scripting.FileSystemObject
Dim myFolder As Scripting.Folder
Dim myFile As Scripting.File

'Excel Related Variables
Dim myWS As Excel.Worksheet
Dim CurRow As Long
Sub ImportTitleBlockTags()
Dim askUser As Integer
askUser = MsgBox("This process will replace the current information in your Excel Sheet!" & vbCrLf & " Do you want to continue?", vbYesNo, "Confirmation")
If askUser = 7 Then
MsgBox ("You chose to exit the import process.")
Exit Sub
End If

'Set Active Sheet as target sheet
Set myWS = Excel.ThisWorkbook.ActiveSheet

On Error GoTo ErrHandler

ErrHandler:
Select Case Err.Number
Case 5
MsgBox "The Cell(4,1) or 'A4' should have valid path to the folder containing drawings."
Exit Sub

Case -2147220102
MsgBox "MicroStation reported tagset was not found!" & vbCrLf & "There is no fix at this moment for these files." _
& vbCrLf & "Future updates might fix this issue. For now simply avoid using such files." _
& vbCrLf & "The current process is terminated. Please restart the process again."
Exit Sub

Case -2147220093
MsgBox "MicroStation reported tag was not found!" & vbCrLf & "Make sure the tags exists in the drawing file."
Exit Sub

Case -2147220101
MsgBox "MicroStation reported tag was not found in the tag set!" & vbCrLf & "Make sure the tag is defined in the tag set."
Exit Sub

End Select
'Current Row can be set according to the Template
CurRow = 6

'Get files from the folder
Set myFolder = myFSO.GetFolder(myWS.Cells(4, 1)) 'This cell must have folder path where the sheets files are

'Get Microstation for file processing
Set oMSApp = New MicroStationDGN.Application

Dim oScanCriteria As New ElementScanCriteria

'Loop through each file
For Each myFile In myFolder.Files
Select Case myFile.Type
Case "Bentley MicroStation Design"  'Case can be different for your install. Make sure you Watch the variable myDGN and find out the myFile.Type and proceed.
'Open Microstation Files for programming
Set myDGN = oMSApp.OpenDesignFileForProgram(myFile.Path, True)
'Write File Name
myWS.Cells(CurRow, 1) = myDGN.Name
oScanCriteria.ExcludeAllTypes
oScanCriteria.IncludeType msdElementTypeTag

I know very little about VBA but I believe that this next section of code basically tells the app to look for tags in sheet models first else look in design models. If I remove the latter part after the else trying to force it to ignore the design models, the app doesn't import the data.

Code:
'Determine which model has tags. Usually the tags are kept in the sheet file with msdModelTypeSheet property
Dim modelCount As Integer
Dim myModel As String
For modelCount = 1 To myDGN.Models.Count
If myDGN.Models(modelCount).Type = msdModelTypeSheet Then
myModel = myDGN.Models(modelCount).Name
ElseIf myDGN.Models(modelCount).Type = msdModelTypeModel Then
myModel = myDGN.Models(modelCount).Name
End If
Next

There is further code but it shouldn't be relevant to the issue as it deals with the tag names.

I've tried asking for help within the VBA section of the Microstation forums but with no luck so I'm hoping that the knowledgeable people here can help shed some light on what's causing my problem. If I can provide any further information please ask as I realise the chances of anyone here being familiar with Microstation is slim.

Many thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top