Skip to content

Instantly share code, notes, and snippets.

@dsisnero
Created August 18, 2016 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsisnero/56a005dcdea0635d555b99ac77a994c0 to your computer and use it in GitHub Desktop.
Save dsisnero/56a005dcdea0635d555b99ac77a994c0 to your computer and use it in GitHub Desktop.
Scrapes text from a cell in Microstation.
Public Sub scrapeFromCell()
'bdoherty 2012 08 09
'scrapes text from the VARTXT cell
'based on code that was Posted by Jon Summers
'on Mon, Jan 2 2012 12:15 PM at bit.ly/TityVa
Dim oCells As ElementEnumerator
Dim oElement As Element
Dim oCriteria As New ElementScanCriteria
Dim oCell As CellElement
Dim oTextNode As TextNodeElement
Dim output As String
Dim sep As String
Const nTextLine As Integer = 2
sep = "~"
oCriteria.ExcludeAllTypes
oCriteria.IncludeType msdElementTypeCellHeader
Set oCells = ActiveModelReference.Scan(oCriteria)
Do While oCells.MoveNext
Set oCell = oCells.Current
oCell.ResetElementEnumeration
If oCell.Name = "VARTXT" Then '<--------change here
Do While oCell.MoveToNextElement
Set oElement = oCell.CopyCurrentElement
If oElement.IsTextNodeElement Then
Set oTextNode = oElement.AsTextNodeElement
Dim line As Integer
For line = 1 To oTextNode.TextLinesCount
output = output & oTextNode.TextLine(line) & sep
Next line
Else
Dim temp As String
temp = oElement.AsTextElement.Text
output = output & temp & sep
End If
Loop
End If
Loop
'Debug.Print output
Dim FileNum As Integer
FileNum = FreeFile
Open "c:\a\scrape.txt" For Append As #FileNum '<--------change here
Print #FileNum, output
Close
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment