Jump to content

Need help of excel script that can data link cell to CAD with a macro button


SSSSS
 Share

Recommended Posts

Hi everyone,

 

I have an excel panel schedule that would like to data link to CAD with a macro button in excel. If destinated CAD file is opened, when I clicked macro button, it will direct me to the CAD and ask me to pick the location to paste the panel schedule. The panel schedule would be data linked to the excel.  

 

Thanks.

Link to comment
Share on other sites

15 hours ago, SSSSS said:

Hi everyone,

 

I have an excel panel schedule that would like to data link to CAD with a macro button in excel. If destinated CAD file is opened, when I clicked macro button, it will direct me to the CAD and ask me to pick the location to paste the panel schedule. The panel schedule would be data linked to the excel.  

 

Thanks.

You should modify the path for open a new template.

See picture below, you have to create a command button in excel, assign the macro below, and try.

 

Sub Macro_Cad()
    Dim acadApp As Object
'Check if AutoCAD is open.
   ' On Error Resume Next
    Set acadApp = GetObject(, "AutoCAD.Application")
    On Error GoTo 0
    
    'If AutoCAD is not opened create a new instance and make it visible.
   If acadApp Is Nothing Then
        Set acadApp = CreateObject("AutoCAD.Application")
        acadApp.Visible = True
   End If
    
    'Check if there is an active drawing.
    On Error Resume Next
    Set acadDoc = acadApp.ActiveDocument
    
    'No active drawing found. Create a new one.
    If acadDoc Is Nothing Then
        Set acadDoc = acadApp.Documents.Add("C:\Users\IO\AppData\Local\Autodesk\AutoCAD Mechanical 2021\R24.0\enu\Template\acad.dwt")
        acadApp.Visible = True
    End If
acadApp.Visible = True
MyScreenPoint = acadDoc.Utility.GetPoint(, "Select Insertion Point: ")
Range("E3").Value = MyScreenPoint(0)
Range("F3").Value = MyScreenPoint(1)
Range("G3").Value = MyScreenPoint(2)
End Sub


image.png.655fa4838f60136eda05c14987adbaf1.png

Link to comment
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.

 Share

×
×
  • Create New...