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.
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
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
try adding the file extension
FileDWGTemplate1 = "C:\Users\Francesco Cacciola\Desktop\Elaborazione\Crea Table\Blocks Index and templates\A3.dwg"
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
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.