Jump to content

Excel Macro VBA script to pastespec in AutoCAD


Recommended Posts

Hi everyone,

 

I wrote the following code, and was expected the selected cell would be copied to AutoCAD with one click. I was able to call the Paste Special command and the Paste Special Window pop up. However, the second "Enter" does not go thru so I have to manually click on the "OK" button in order to move forward, which supposed to be done by the code. I checked and the code just stopped after the first "Enter". Below is the code and I have attached the picture of Paste Special Windows (image006) for your reference.

 

Another question, even though I enabled the macro, the alert message still popup every time I run the macro. Why does it happen? (Please see the picture image007)

 

Thanks everyone.

 

Sub Button3_Click()

 

    Range("E2:G3").Select

    Selection.Copy

 

    Dim acadApp As Object

 

    Set acadApp = GetObject(, "AutoCAD.Application")

    On Error GoTo 0

   

If acadApp Is Nothing Then

 

Application.CutCopyMode = True

MsgBox "AutoCAD is not running", vbOKOnly, "Error"

Cells(3, 5).Select

 

Else: AppActivate "AutoCAD"

 

acadApp.WindowState = 3

   

acadApp.Visible = True

SendKeys ("pastespec")

SendKeys "{ENTER}"

 

SendKeys "{ENTER}" '<-- This Enter does not work

 

 

End If

End Sub

image006.jpg

image007.jpg

Link to post
Share on other sites
BIGAL

If you want text then why not just do that you can make text from excel telling Autocad what to create. 

 

Some examples I dont have a text example these are cut from some sample code can post.

Set lineobj = acadDoc.ModelSpace.addline(startpoint, endpoint)

 Set circobj = acadDoc.ModelSpace.addcircle(cenpoint, rad)

Set Pline = acadDoc.ModelSpace.AddLightWeightPolyline(cords)

 

Set Text = acadDoc.ModelSpace.Addtext....................

 

A good link 

 

Edited by BIGAL
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...