[VBA: VB6] Using excel from another application
Here is a little routine to call Excel from VB6 or another Office application.
Paste in a general module (eg Module1)
In VBA>> Insert>> Module and paste in the window ...
In VB6>> Project>> Add a module, and paste into this window ...
Dim EX As New Application
Public Book As Workbook
Public Sheet As Worksheet
'Don’t forget to add the reference ..
'Microsoft Excel X,X object librairy
Sub AddExcel ()
Set EX = CreateObject ( "Excel.Application")
EX.Visible = True
Set Book = EX.Workbooks.Add
'All the functions are available with Application Book
Set Sheet = Book.Sheets (1)
Example:
Sheet.Name = "The Sheet"
With Sheet
. [A1] = "This is the cell A1"
. [A2] = "This is the A2"
. Columns ("A:A"). ColumnWidth = 23.14
End With
'All the functions are available with excel sheet.
End Sub