VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with InsertBlock from another file- Error 424

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
1258 Views, 7 Replies

Problem with InsertBlock from another file- Error 424

Hi everybody,
I have a problem with the InsertBlock in a VBA code....
When i click "run" the Macro VBA and the code arrive until -InsertBlock- where i have the same Error that is shows in the figure.

I tryed different ways that are show in yellow in the figure...but the results were always "Error 424 - Object required"


Does anyone knows where is my mystake???

 

Thank you very much in advance.

 

 

Image.PNG

7 REPLIES 7
Message 2 of 8
norman.yuan
in reply to: Anonymous

You should paste your code into the post, rather than a picture, so that is easier to read, and you can include more relevant code.

 

According to the picture, are you saying that event this line also results in the same error

Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(....)?

 

My bet is that among the 4 line of codes (3 commented out), this line is the line that SHOULD work (assume the variable "FileDWGTemplate1" supplies a valid block file name).

 

The other 3 lines that do not work (with the given error) is very likely because of the variable "ThisDocument" and/or "acadDoc" are not properly initialized. Since you did not show the code how they are declared/initialized, it is only my guess.

 

Again, when showing code in post, use the "insert code" button in the toolbar, so that you can easily post all relevant code in read-friendly format.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 8
Anonymous
in reply to: norman.yuan

This is the Code

 

 

Sub Select_Folder_Template()

 

Dim insertionPoint As Variant
Dim blockObj As AcadBlock
Dim blockRefObj As AcadBlockReference
Dim blockRefObj2 As AcadBlockReference
Dim varAttributes As Variant

Dim FolderDWG As String

ThisDrawing.ActiveLayout = ThisDrawing.Layouts("Model")

Layout_Size_Template.show
FolderDWG = ReturnFolderDWG
FileDWGTemplate1 = "C:\Users\Francesco Cacciola\Desktop\Elaborazione\Crea Table\Blocks Index and templates\A3"
FileDWGTemplate2 = "C:\Users\Francesco Cacciola\Desktop\Elaborazione\Crea Table\Blocks Index and templates\A3"

insertionPoint = ThisDrawing.Utility.GetPoint(, "Select the Point where you want to import and start the model.")

MsgBox FileDWGTemplate1 & vbLf & vbLf & FileDWGTemplate2

 

MsgBox insertionPoint(0) & vbLf & vbLf & insertionPoint(1)

 

Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPoint, FileDWGTemplate1, 1#, 1#, 1#, 0)
blockRefObj.Explode

Set blockRefObj2 = ThisDrawing.ModelSpace.InsertBlock(insertionPoint, FileDWGTemplate2, 1#, 1#, 1#, 0)
blockRefObj2.Explode

ThisDrawing.ActiveLayout = ThisDrawing.Layouts("Model")
End Sub

Message 4 of 8
Anonymous
in reply to: Anonymous

try adding the file extension

 

FileDWGTemplate1 = "C:\Users\Francesco Cacciola\Desktop\Elaborazione\Crea Table\Blocks Index and templates\A3.dwg"
Message 5 of 8
Anonymous
in reply to: Anonymous

Excuse me, there are ".dwg" in the code.
During the copy And paste i forget it.
So the problem It isn't this.
Message 6 of 8
Anonymous
in reply to: Anonymous

Please be sure you’re posting relevant code and help people trying to help you

Now, post the full actual code that throws the error and clearly specify which line is throwing it
Message 7 of 8
Anonymous
in reply to: Anonymous

This is the Code

 

 

Sub Select_Folder_Template()

 

Dim insertionPoint As Variant
Dim blockObj As AcadBlock
Dim blockRefObj As AcadBlockReference
Dim blockRefObj2 As AcadBlockReference
Dim varAttributes As Variant

Dim FolderDWG As String

ThisDrawing.ActiveLayout = ThisDrawing.Layouts("Model")

Layout_Size_Template.show
FolderDWG = ReturnFolderDWG
FileDWGTemplate1 = "C:\Users\Francesco Cacciola\Desktop\Elaborazione\Crea Table\Blocks Index and templates\A3.dwg"
FileDWGTemplate2 = "C:\Users\Francesco Cacciola\Desktop\Elaborazione\Crea Table\Blocks Index and templates\A3.dwg"
insertionPoint = ThisDrawing.Utility.GetPoint(, "Select the Point where you want to import and start the model.")

MsgBox FileDWGTemplate1 & vbLf & vbLf & FileDWGTemplate2

 

MsgBox insertionPoint(0) & vbLf & vbLf & insertionPoint(1)

 

Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPoint, FileDWGTemplate1, 1#, 1#, 1#, 0)
blockRefObj.Explode

Set blockRefObj2 = ThisDrawing.ModelSpace.InsertBlock(insertionPoint, FileDWGTemplate2, 1#, 1#, 1#, 0)
blockRefObj2.Explode

ThisDrawing.ActiveLayout = ThisDrawing.Layouts("Model")
End Sub

Message 8 of 8
Anonymous
in reply to: Anonymous

you're missing the other info I asked you: clearly specify which line is throwing the error

 

it's the line that gets highlighted when you press the "Debug" button on the error messagebox

 

or you can step through your code line by line by pressing F8 until you reach the line that throws it

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta