I have a VBA application in Excel that extracts tags data from DGN files and I am stumped as to why the code below will not work. At the highlighted line oTags is populated with the tags data but as soon as the highlighted line is processed I get an error -2147417848 Automation error "The object invoked has disconnected from its clients."
Does anyone know what would cause this? It seems like I might be missing a step somewhere.
Best Regards,John Davidson
Set myDGN = oMSApp.OpenDesignFileForProgram(myFile.Path, True) oScanCriteria.ExcludeAllTypes oScanCriteria.IncludeType msdElementTypeCellHeader 'Only process Default Model Set oModel = myDGN.DefaultModelReference Set oEnumerator = oModel.Scan(oScanCriteria) Do While oEnumerator.MoveNext Set oHost = oEnumerator.Current If (oHost.HasAnyTags) Then Dim vtValue As Variant oTags = oHost.GetTags() ' process tag array For j = LBound(oTags) To UBound(oTags) vtValue = oTags(j).Value Debug.Print "Tag [" & CStr(j) & "]" = " & CStr(vtValue)" Next j End If
Unknown said: Dim vtValue As Variant ... vtValue = oTags(j).Value
Other have noted that there's some incompatibility between a MicroStation VBA Variant and an Office VBA Variant. It happens with Access VBA as well as Excel VBA.
There's nothing we can do about it other than report the problem to Bentley Systems.
Regards, Jon Summers LA Solutions
Thanks Jon,
Is there any other method of extracting data from DGN files to Excel using Excel.
My users are using both Bentley Navigator and Excel and I am trying to make the data exchange between the two as user friendly and simple as possible, is it possible to initiate a MicroSation macro form Excel.
Best Regards,
John Davidson
I found For Each statement can work in this case.
Dim tag As Variant
For Each tag in oTags
MsgBox tag.value
Next
HTH, YongAn
Unknown said: Dim tag As Variant For Each tag in oTags MsgBox tag.value Next
Dim tag As Variant For Each tag in oTags MsgBox tag.value Next
Is that in plain old MicroStation or in Office VBA?
Hi Jon,
This is in Office 2012 VBA. It can work.
Regards, YongAn
Answer Verified By: John D
That's a useful observation. What others have reported is this failure...
Dim oTag As TagElement... get tag from somewhereDim vtValue As VariantvtValue = oTag.Value ' fails in Office VBA
If you read my code again, you will find I didn't define the returned tag value as Variant, I defined tag element as Variant (used in For Each statement). And I really got the correct result by this way. If you need test case, please let me know.
Unknown said:I defined tag element as Variant (used in For Each statement). And I really got the correct result by this way.
Yes, but why does that work? And why does it fail when one attempts to assign Tag.Value to a Variant?
Thanks for all your feedback, since I am unable to get this to work I have written that part of the process to run inside Navigator. It would have been nice to have all the processing done from Excel with one user input, but it will still be OK.
Thanks again Guys,
John.