Dim x1 as Object 'either put this declaration at Form level or make it static.
Set x1 = CreateObject("Excel.Application")
x1.Visible = True
x1.Workbooks.Add 'next three commands specific to object
x1.Range("A1").Value = "Hello World"
' assign value in spreadsheet to a control on our Form
x1.Range("A2").Value = txtPerson.text
xl.Workbooks.Open "c:invoice.xls" 'open another doc
x1.ActiveWorkbook.Close ! close workbook (follow by "False" for no prompt)
x1.Quit !close App
Excel Example, with Error Handling
Dim xl As Excel.Application
Dim xlwb As Excel.WorkBook
On Error Resume Next
set xl = CreateObject ("Excel.Application")
set xlwb = xl.Workbooks.Open ("c:ook1.xls ")
If Err <> 0 Then
MsgBox "Unable to open workbook"
UnLoad Me
End If
Dim xl As Excel.Application
Dim xlwb As Excel.WorkBook
On Error Resume Next
set xl = CreateObject ("Excel.Application")
set xlwb = xl.Workbooks.Open ("c:ook1.xls ")
If Err <> 0 Then
MsgBox "Unable to open workbook"
UnLoad Me
End If
|