在CAD vba中如何打开指定路径的EXCEL文件
因为EXCEL vba稍微熟悉些,想把很多文字写入到定义好的EXCEL模板里处理,请教下如何在CAD VBA中打开指定路径的EXCEL文档(例如D:\A.XLS),然后往A1单元格填入数据?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
感谢指导!!!!!!!!
页:
[1]