-----Original Message-----
From: Alessandria, Gabriel <galessan@apsf.com.ar>
To: 'vb-esp@ccc.uba.ar' <vb-esp@ccc.uba.ar>
Date: Monday, August 31, 1998 5:01 PM
Subject: (VB-ESP) Integracion con EXCEL desde VB
Por favor, alguien me puede enviar un ejemplo de codigo de como
hacer para desde visual basic leer una planilla de excel, recorrerla,
etc con el objeto MICROSOFT EXCEL QUE SE PUEDE USAR DESDE VB ?
El siguiente codigo crea un "Worksheet" llena una serie de celdas con datos
al azar y, con los datos introducidos en ellas, un grafico (chart)
estadistico.
Dim obj As Object
Public Sub Main()
Dim wk As Object
Dim ws As Object
Dim ch As Object
Dim ra As Object
Dim y As Integer, x As Integer
Set obj = CreateObject("Excel.Application.8") ' El 8 es por la version
8 de Excel
obj.Visible = True
Set wk = obj.Workbooks.Add
Set ws = wk.Worksheets.Add
ws.Name = "Manu's Nook Worksheet"
ws.Activate
With obj.ActiveSheet
With .Cells(1, 1)
.Value = "Manu's Nook Software Presents"
With .Font
.Bold = True
.Name = "Verdana"
.Size = 24
End With
End With
With .Cells(2, 1)
.Value = "The ultimate list method"
With .Font
.Name = "Verdana"
.Size = 14
End With
End With
With .Cells(3, 1)
.Value = "Please, don't touch this data lines!!!"
With .Font
.Name = "Verdana"
.Size = 10
End With
End With
Randomize
For y = 1 To 12 ' Leer correspondencias mas abajo
For x = 5 To 8
.Cells(x, y).Value = Rnd * 50 + 1
Next
Next
Set ra = ws.Range("A5:L8") ' A = 1 (y), L = 12 ("y" al final de
bucle); 5 = x, 8 = x (al final)
Set ch = obj.Charts.Add
With ch
.Name = "Manu's Nook SuperCharty"
.HasTitle = True
.ChartTitle.Text = "The SuperCharty demo in action!!"
.ChartType = xlLine
.SetSourceData ra
.Location xlLocationAsObject, ws.Name
End With
End With
Set obj = Nothing
End Sub
Manu
-------------------------------------------------------------------
Spanish people from Luxembourg (Europe)
manuel@ip.lu
Resumen