Can anyone please let me know why my code is not working? I keep receiving Error 424: Object Required. I'm pretty new to VBA and coding so it might be something very simple. This is what I would like my code to do:
This is my code:
Sub Init() Dim oText As TextElement Set oText = ElementEnumerator.Current.AsTextElement Dim content As String content = oText.Text CreateLink contentEnd SubSub CreateLink(ByVal content As String) Dim strURL As String strURL = "http://www.google.com" & "/" & content Debug.Print "My URL=" & strURL CadInputQueue.SendKeyin "ELEMENT CREATE LINK URL " & strURLEnd Sub
You should see the line which causes the error and tell it us...
But this case seems pretty simple: Neither You've declared the variable ElementEnumerator nor did You assign any value to it - at least not in the code we can see here.
Robert
Unknown said:Dim ee As ElementEnumerator Dim oText As TextElement Set oText = ee.Current.AsTextElement
You've declared a variable named ee. It's a reference to a class of type ElementEnumerator. Right now, you haven't initialised that object: it's an empty chunk of memory. That explains the error message.
An ElementEnumerator is used to enumerate elements. The question is "What elements do you want to enumerate?" Often, you want to scan a DGN model to examine its graphic elements. The Scan method of ModelReference does exactly that and returns a valid ElementEnumerator. Look that up in VBA help, and write something like this:
Set ee = ActiveModelReference.Scan Do While ee.MoveNext Dim oElement As Element Set oElement = ee.Current If oElement.IsTextElement Then Dim oTextElement As TextElement Set oTextElement = oElement.AsTextElement ' Now you can use the properties and methods of TextElement Debug.Print "Text=" & oTextElement.Text EndIf Loop
Regards, Jon Summers LA Solutions