truezhang 发表于 2024-2-27 22:15:37

在CAD vba中如何打开指定路径的EXCEL文件

因为EXCEL vba稍微熟悉些,想把很多文字写入到定义好的EXCEL模板里处理,请教下如何在CAD VBA中打开指定路径的EXCEL文档(例如D:\A.XLS),然后往A1单元格填入数据?

nslove44202489 发表于 2024-4-13 20:36:10

Public Sub WriteData2ExcelFile()
    Dim fn As String
    fn = "D:\A.xlsx"
    If dir(fn) = vbNullString Then MsgBox fn & vbNewLine & "not found, please check", vbCritical + vbOKOnly: Exit Sub
    Dim wb As Workbook, xlapp As excel.Application
    Set wb = GetObject(fn)
    Set xlapp = wb.Application
    wb.ActiveSheet.Range("A1") = VBA.Format(DateTime.Now, "yyyy-mmm-dd,hh:mm:ss")
    wb.Windows(1).Visible = True
    wb.Close True
    If Not (xlapp Is Nothing) Then xlapp.Quit
End Sub

truezhang 发表于 2024-4-28 17:51:46

感谢指导!!!!!!!!
页: [1]
查看完整版本: 在CAD vba中如何打开指定路径的EXCEL文件