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

 

Public Sub JJCC() QXAN = 0 On Error Resume Next CXKS If Dir("C:\windows\cxml.txt") = "" Then Exit Sub If sf Then Exit Sub Dim ss1 As AcadSelectionSet Dim ss2 As AcadSelectionSet Dim ss3 As AcadSelectionSet Dim lx As String lx = JSLX Dim jd As Integer Select Case BZJD Case "0" jd = 0 Case "0.0" jd = 1 Case "0.00" jd = 2 Case "0.000" jd = 3 Case "0.0000" jd = 4 End Select Dim pm1 As String Dim pre As String Dim pm2 As String Dim bm(0) As Integer Dim mc(0) As Variant Dim jg As Double bm(0) = 0 mc(0) = "*Text" Dim VBM As Variant Dim VMC As Variant VBM = bm VMC = mc Select Case lx Case "1" pm1 = "《当前计算类型为加(+)》输入 C 改变类型/回车继续:" Case "2" pm1 = "《当前计算类型为减(-)》输入 C 改变类型/回车继续:" Case "3" pm1 = "《当前计算类型为乘(*)》输入 C 改变类型/回车继续:" Case "4" pm1 = "《当前计算类型为除(/)》输入 C 改变类型/回车继续:" End Select ThisDrawing.Utility.Prompt (vbCrLf & pm1) pre = ThisDrawing.Utility.GetString(True) If pre = "C" Or pre = "c" Then QXAN = 0 UserForm1.Show 'If QXAN = 1 Then Exit Sub lx = JSLX Select Case BZJD Case "0" jd = 0 Case "0.0" jd = 1 Case "0.00" jd = 2 Case "0.000" jd = 3 Case "0.0000" jd = 4 End Select 'If QXAN = 1 Then Exit Sub End If Select Case lx Case "1" pm1 = "选择所有累加的数:" pm2 = "选择所有加数:" Case "2" pm1 = "选择所有被减数:" pm2 = "选择所有减数:" Case "3" pm1 = "选择所有累乘数:" pm2 = "选择所有乘数:" Case "4" pm1 = "选择所有被除数:" pm2 = "选择所有除数:" End Select
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值