Here's my standard Excel chit-chat program that I post here about every five
days or so.
Option Explicit
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Private Sub Command1_Click()
xlSheet.Cells(1, 1).Value = Text1.Text
xlSheet.Cells(2, 1).Value = Text2.Text
xlSheet.Cells(3, 1).Value = Text3.Text
Text4.Text = Format(CCur(Abs(xlSheet.Cells(4, 1).Value)), "##,###.00")
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Set xlApp = New Excel.Application
Set xlBook = GetObject("o:\Excel Demo\book1.xls")
Set xlSheet = xlBook.Worksheets("Sheet1")
End Sub
Private Sub Form_Unload(Cancel As Integer)
xlBook.Close False
xlApp.Quit
Set xlApp = Nothing
End Sub
And yes, the Set xlApp = New Excel.Application starts Excel automatically.
This demo program writes data to cells in the Excel spreadsheet and fetches
data from cells in the Excel spreadsheet.
Eric
Quote:
> Sorry that this is probably an easy question, but I have an array of data
> which i wish to write to an existing Excel file. So far I have an array of
> long values called MyArray() and :
> Dim myxl As Object
> Dim x As Integer
> Set myxl = GetObject("c:\stats1.xls")
> Set xlsheet = myxl.worksheets("Sheet1")
> For x = 1 To 10
> xlsheet.Cells(2 + x, 2) = Myarray(x)
> Next x
> but this doesn't seem to write to the file, no error message appears. Does
> Excel need to be open ? If so, is there a way of doing this without Excel
> being open ? Can anyone help ?
> Thanks in advance
> Alistair