excel打开并操作CAD(excel-vba实现)_另附:CAD打开excel

        excelvba可实现调用cad应用程序,并通过excel内置api弹窗实现打开、另存CAD

文件(cad-vba弹窗功能较为麻烦),代码如下(在excel_vba环境下操作):

Sub excel_vba打开另存并操作CAD文件()
Dim cad As Object
Set cad = CreateObject("autocad.Application")
cad.Visible = True
cad.documents.Add

On Error Resume Next
With excel.Application.FileDialog(msoFileDialogOpen)
    .Title = "请选择你要的文件"
    .AllowMultiSelect = True
    .InitialFileName = "C:\Users\Administrator\Desktop\"
    .Filters.Clear
    .Filters.Add "excel files", "*.xls,*.xlsx,*.dwg"
    If .Show = True Then
    Set gof = .SelectedItems
    End If
End With
cad.Application.documents.Open (gof.Item(1))
MsgBox "另存为"
With excel.Application.FileDialog(msoFileDialogSaveAs)
    .Title = "另存为"
    .AllowMultiSelect = True
    .InitialFileName = "C:\Users\Administrator\Desktop\"
    If .Show = True Then
    Set gof1 = .SelectedItems
    End If
End With
cad.Application.activedocument.SaveAs (gof1.Item(1))

End Sub

另附excel文件可参考。 

以下代码为在CADVBA环境下打开excel并操作的代码:

Sub CAD打开excel_cadvba实现()
Dim excel As Object
Dim excelSheet As Object
    ' Start Excel
    On Error Resume Next
    
    Set excel = GetObject(, "Excel.Application")
    
    If Err <> 0 Then
        Err.Clear
        Set excel = CreateObject("Excel.Application")
            
        If Err <> 0 Then
            MsgBox "Could not load Excel.", vbExclamation
            End
        End If
    End If
    
   
    
    excel.Visible = True
    excel.Workbooks.Add
    excel.Sheets("Sheet1").Select
    Set excelSheet = excel.ActiveWorkbook.Sheets("Sheet1")
End Sub

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山水CAD插件定制

你的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值