create script for data link

create script for data link

jm.sagarduy
Contributor Contributor
3,562 Views
7 Replies
Message 1 of 8

create script for data link

jm.sagarduy
Contributor
Contributor

I need to create a script to link data from excel in several files autocad.

0 Likes
Accepted solutions (1)
3,563 Views
7 Replies
Replies (7)
Message 2 of 8

Jonathan3891
Advisor
Advisor

Unfortunately a script will work properly. On the "Pastespec" menu you should use "Paste Link" and you either have to press the radio button manually or press "Alt+L".

 

However you can accomplish this with VBA in excel with ease!

 

Open excel, Press "Alt+F11" to open VBA.

Insert > Module

 

Paste this code:

Sub sbACAD()
Dim objAutoCAD As Object

On Error Resume Next
Set objAutoCAD = GetObject(, "AutoCAD.Application")
On Error GoTo 0

If objAutoCAD Is Nothing Then
          
Application.CutCopyMode = False
MsgBox "AutoCAD is not running", vbOKOnly, "Error"
Cells(3, 5).Select
          
Else: AppActivate "AutoCAD"
objAutoCAD.WindowState = 3

SendKeys ("pastespec")
SendKeys "{ENTER}"
Application.Wait Now + TimeValue("00:00:01")
SendKeys ("%(L)")
SendKeys "{DOWN}"
SendKeys "{ENTER}"

End If
End Sub

 

You can even have the table placed automatically with this: Make sure to change the coordinates to what you want.

Application.Wait Now + TimeValue("00:00:12")
SendKeys ("13.767{TAB}21.044")
SendKeys "{ENTER}"

I inserted a wait time because for me Datalinks are a bit slow. 

 

Once you save the macro press "Alt+F8" to open the macro window.

 

Dont forget to highlight your cells and press "Ctrl+C" before running the macro!!!


Jonathan Norton
Blog | Linkedin
0 Likes
Message 3 of 8

jm.sagarduy
Contributor
Contributor

jhonatan thanks for the response.
I'm testing the macro you have sent me but I error in the following line:
Else: AppActivate "AutoCAD"
with this macro it is what I get dump a table autocad excel?
Best Regards.

Jesus Maria Sagarduy.

 
 
0 Likes
Message 4 of 8

Jonathan3891
Advisor
Advisor
Do you have a drawing open?

Post your excel file and let me take a look

Jonathan Norton
Blog | Linkedin
0 Likes
Message 5 of 8

jm.sagarduy
Contributor
Contributor

hello jhonatan
I've been a little busy these days, I am now taking up the work with data link.
you excel file attachment sending and file cad with whom I generally dwg's collection. each excel sheet must be a worksheet cad.
reggards.

 

Jesús Mª Sagarduy

 

0 Likes
Message 6 of 8

Jonathan3891
Advisor
Advisor

I'm unable to load an xlsm file here, so I uploaded it to my dropbox.

 

Download from here

 

I created a button next to each table that says "<Datalink".

Upon pushing the button, Excel will switch to AutoCAD and automate the Datalink process.

 

If AutoCAD is not running, it will display a message saying, "AutoCAD is not running!"

 

I hope it helps!


Jonathan Norton
Blog | Linkedin
0 Likes
Message 7 of 8

jm.sagarduy
Contributor
Contributor
Accepted solution

Hi Jonathan
thank you very much for excel you have sent me. I will be very useful !!
a greeting from Bilbao.
Jesus Maria Sagarduy.

0 Likes
Message 8 of 8

joao.sousa3U7LY
Explorer
Explorer

Hi Jonathan an J. Maria.

 

Could you please reupload the Excel file ?

 

Thanks!!

0 Likes