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

create or open excel file

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
gopal.singh
2894 Views, 4 Replies

create or open excel file

I am trying to create an excel file using autocad vba using following code but I get compile error as User-defined type not defined

 

Dim oApp_Excel As Excel.Application
Dim oBook As Excel.workbook

Set oApp_Excel = CreateObject("EXCEL.APPLICATION")
Set oBook = oApp_Excel.workbooks.Add

4 REPLIES 4
Message 2 of 5
norman.yuan
in reply to: gopal.singh

You need to add "Microsoft Excel [Version] Library" as reference (VBAIDE->Menu->Tools->References...)

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 5
gopal.singh
in reply to: norman.yuan

thanks norman

Message 4 of 5
gopal.singh
in reply to: norman.yuan

I want to output into excel the name, layer and center co-ordinate of selected circle . I succeed in name and layer but could not get centre co-ordinate.

I used following code.

.

wrks.Range("A" & rownr) = obj.Name
wrks.Range("B" & rownr) = obj.Layer
wrks.Range("C" & rownr) = obj.EffectiveName
wrks.Range("D" & rownr) = obj.CentrePointx
wrks.Range("E" & rownr) = obj.CentrePointy
wrks.Range("F" & rownr) = obj.CentrePointz

Message 5 of 5
norman.yuan
in reply to: gopal.singh

It looks like you need a bit study on what type of objects you are dealing with in AutoCAD. You can open AutoCAD, go into VBA Editor, open Object Browser window and see all the objects available in AutoCAD object model.

 

From the few lines of code, it is not clear what the "obj" is: a block reference (AcadBlockReference), or a circle (AcadCircle)?

 

If it is the former, then an AcadBlockReferece does nto have property like "CenterPoint..."; if it is an AcadCircle, it should have a property Center, but not CentrePointX/Y/Z and it does not have property "Name" or "EffectiveName"

 

So, you need to know WHAT AcadEntity or AcadEntities you are dealing with, and know what properties the target entity has.

 

Now, assume you are targeting a circle (AcadCircle), and needs to know its centre's coordinate, you do:

 

Range(...)=obj.Center[0]

Range(...)=obj.Center[1]

Range(...)=obj.Center[2]

 

Because Center propery is an 3-element array of Double values, representing X,Y and Z of coordinate

 

If you are targeting block, then there is no property Center, Instead, it has InsertionPoint property.

 

If you are targeting mixed entity types, you then need to treat them differently with the help of 

 

If TypeOf obj is AcadCicle Then

  ''Do something

ElseIf TyoeOf obj Is AadBlockReference Then

  ....

Else

  ....

End If

 

Norman Yuan

Drive CAD With Code

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost