关于vb外部驱动excel
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim ExcelIsRunning As Boolean
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelIsRunning = False
If ExcelIsRunning = False Then
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlsheet = xlBook.Worksheets(1)
xlsheet.Name = "xsw"
With xlsheet
.Range("a1").Value = "hello baby!"
.Range("a2").Value = "重新建立"
End With
Else
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlsheet = xlBook.Worksheets(1)
xlsheet.Name = "xsw1"
With xlsheet
.Range("a1").Value = "hello baby!"
.Range("a2").Value = "直接引用"
End With
End If