|
Option
Explicit
'Används för att underlätta tilldelning av värden för cellområdet.
Option
Base
1
Private
Sub
XL_Automation_Click()
'© 2004
Alla rättigheter XL-Dennis
Dim
xlApp
As
Excel.Application
Dim
xlWBook
As
Excel.Workbook
Dim
xlWSheet
As
Excel.Worksheet
Dim
xlRange
As
Excel.Range
Dim
iData(1
To
2)
As
Integer,
i
As
Integer
Dim
stPathName
As
String
stPathName = App.Path
&
"\Automation.xls"
'Eventuellt tidigare version av arbetsboken tas bort.
If
Dir(stPathName)
<>
""
Then
Kill
stPathName
End
If
'Tilldelar arrayen värden.
iData(1)
=
"1000"
iData(2)
=
"2000"
'Instansierar objekten
Set
xlApp = New
Excel.Application
'Skapar
en arbetsbok med ett arbetsblad.
Set
xlWBook = xlApp.Workbooks.Add(xlWBATWorksheet)
Set
xlWSheet = xlWBook.Worksheets(1)
With
xlWSheet
Set
xlRange = .Range("A1:A2")
End
With
With
xlApp
'Visar
Excel-fönstret.
.Visible =
True
'Användaren får kontroll över Excel.
.UserControl
=
True
.ScreenUpdating
=
False
End
With
xlWSheet.Name =
"Automation"
For
i =
1
To
2
xlRange(i,
1).Value
= iData(i)
Next
i
'Spara
arbetsboken.
xlWBook.SaveAs Filename:=stPathName
xlApp.ScreenUpdating =
True
Set
xlRange =
Nothing
Set
xlWSheet =
Nothing
Set
xlWBook =
Nothing
Set
xlApp =
Nothing
End
Sub |