mikewolf2k 发表于 2017-8-16 12:54:21

Sub LinkExcel(ExcelApp)
    On Error Resume Next
    Set ExcelApp = GetObject(, "Excel.application")
    If Err Then
      Err.Clear
      Set ExcelApp = CreateObject("Excel.application")
      If Err Then
            MsgBox ("不能运行Excel,请检查是否安装了Excel")
            Exit Sub
      End If
      ExcelApp.Application.Visible = True
      ExcelApp.Workbooks.Add
    End If
    ExcelApp.StatusBar = "Ready"
End Sub

mikewolf2k 发表于 2017-8-16 12:55:26

参考里面要引用excel object library

906379829 发表于 2017-8-16 15:57:59

vbcad 发表于 2017-8-15 19:23
Dim MyPath As String, MyName As String
Dim objExcel As Object, objBook As Object, objSheet As Objec ...

Public Sub 导材料实验()
Dim MyPath As String
Dim objExcel As Object, objBook As Object
Dim objSheet As Excel.Workbook

Set objExcel = CreateObject("Excel.Application") '建立EXCEL对象


MyPath = Dir(ThisDrawing.Path & "\*.xls")   ' 指定路径为当前脚本目录。

Do While MyPath <> "" ' 开始循环。
      Set objSheet = Workbooks.Open(ThisWorkbook.Path & "\" & MyPath)
      Set objBook = objExcel.Workbooks.Open(FilePath) '打开表格文件
   
    MyPath = Dir ' 查找下一个
Loop
End Sub
我用的你的程序,稍作修改做的,运行到Dim objSheet As Excel.Workbook
提示用户类型未定义

mikewolf2k 发表于 2017-8-16 16:02:31

906379829 发表于 2017-8-16 15:57
Public Sub 导材料实验()
Dim MyPath As String
Dim objExcel As Object, objBook As Object


参考里面要引用excel object library

906379829 发表于 2017-8-16 17:35:44

mikewolf2k 发表于 2017-8-16 16:02
参考里面要引用excel object library

明白了,就是引用栏里添加excel

elepeipei 发表于 2017-11-7 16:13:48

不知道打开后关闭excel怎么写,我只想读取数据,但是打开excel后屏幕上看不到cad图形
页: 1 [2]
查看完整版本: 求教大神,在CAD VBA程序里面如何打开这个CAD文件路径下的一个excel文件