您应该修改打开新模板的路径。
请参见下图,您必须在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
|