SSSSS 发表于 2022-7-6 20:35:10

需要excel脚本的帮助

大家好,
 
我有一个excel面板时间表,希望通过excel中的宏按钮将数据链接到CAD。如果打开了目标CAD文件,当我单击“宏”按钮时,它会将我引导到CAD,并要求我选择粘贴面板明细表的位置。面板明细表将是链接到excel的数据。  
 
谢谢

PeterPan9720 发表于 2022-7-6 22:24:45

您应该修改打开新模板的路径。
请参见下图,您必须在excel中创建一个命令按钮,分配下面的宏,然后重试。
 

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
页: [1]
查看完整版本: 需要excel脚本的帮助