Hi! I'm updating some text from excel to Microstation. Until now I'd been able to update Text and Tags, but I have problems with Text nodes, here is my code:
If myWS.Cells(FileRow, 2) = "NODE" Then Set myNode = myDGN.GetElementByID(myID) 'Store ID High and Low myNode.TextLine(1) = myWS.Cells(FileRow, 4) 'Store new Textnode Value myNode.Rewrite 'Write TextNode End If
The error is "Run time error -69652(ffeefec) at the line three. I have been looking for information regarding the text nodes, but I can't find something similar, even in the help files.
Thanks!
myNode.TextLine(1) = myWS.Cells(FileRow, 4) 'Store new Textnode Value
You need to be sure that myNode.TextLine(1) exists, and you need to be sure that myWS.Cells(FileRow, 4) is a valid range.
Use VBA's Debug.Assert to validate your assumptions:
Dim nTextLine As Long nTextLine = 1 Debug.Assert nTextLine <= myNode.TextLinesCount myNode.TextLine(nTextLine) = ... ... Dim cellText As String cellText = myWS.Cells(FileRow, 4) Debug.Assert 0 <= Len (cellText) Debug.Print "Assign '" & cellText & "' to TextLine(" & CStr(nTextLine) & ")" myNode.TextLine(1) = cellText
Regards, Jon Summers LA Solutions
Hi Jon, thanks.
They both exist, I rewrite this code at Excel
Dim myNode As TextNodeElement
If myWS.Cells(FileRow, 2) = "NODE" Then Set myNode = myDGN.GetElementByID(myID) 'Store ID High and Low MsgBox (myNode.TextLine(1)) MsgBox (myWS.Cells(FileRow, 4)) myNode.TextLine(1) = myWS.Cells(FileRow, 4) 'Store new Textnode Value HERE IS WHEN DE ERROR START myNode.Rewrite 'Write TextNode End If
The message boxes show me exactly the value of the node (In my case is "A") and the value of the cell (In my case is "NODE123") but the error is the -2147218399 "Bad element"
Roberto Cano said:
MsgBox (myNode.TextLine(1)) MsgBox (myWS.Cells(FileRow, 4))
Debug.Print comes in useful here. The following code is similar, but the text appears in VBA's Immediate window:
Debug.Print "myNode.TextLine(1): " & myNode.TextLine(1) Debug.Print "myWS.Cells(FileRow, 4): " & myWS.Cells(FileRow, 4)
Yes, it works, it show me
myNode.TextLine(1): A myWS.Cells(FileRow, 4): NODO111
But the error is the same, in the line
Is really important for my my program update node text, How can I avoid this error?
But the error is the same
TextNodeElements seem to be troublesome in VBA. Gary Manuel had a similar problem with Text Nodes.
Does it make any difference if you copy the text to a new variable before assignment?
Dim s As String s = myWS.Cells(FileRow, 4) myNode.TextLine(1) = s
No, unfortunately it don't work, the error is now at line
myNode.TextLine(1) = s
"BAD ELEMENT"