Crear grafico de excel con VB6
Publicado por Alejandra (3 intervenciones) el 06/05/2008 18:04:54
Hola, necesito crear por codigo un grafico de excel con VB6, logro crear el objeto pero no puedo asignarle el grafico, ni nada, me dice que son propiedades que corresponden. Les muestro una copia de lo que hice, a ver si alguien me puede ayudar.
Dim ExcelApp As Object
Dim ExcelWorkbook As Object
Dim ExcelSheet As Object
Dim ExcelChart As Object
Dim ExcelChart2 As Object
Dim strsql As String
Dim s As Integer
Dim t As Integer
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelWorkbook = ExcelApp.Workbooks.Add 'Open(strGIS & " eportesMED-Ensayos.xls")
Set ExcelSheet = ExcelWorkbook.Worksheets(1)
Set ExcelChart = ExcelSheet.ChartObjects.Add(5, 440, 690, 150)
Set ExcelChart2 = ExcelSheet.ChartObjects.Add(5, 595, 690, 140)
'configuro la página
ExcelSheet.PageSetup.PrintTitleRows = ""
ExcelSheet.PageSetup.LeftMargin = ExcelApp.InchesToPoints(0.590661181102362)
ExcelSheet.PageSetup.RightMargin = ExcelApp.InchesToPoints(0.196850393700079)
ExcelSheet.PageSetup.TopMargin = ExcelApp.InchesToPoints(0.393700078740158)
ExcelSheet.PageSetup.BottomMargin = ExcelApp.InchesToPoints(0.393700078740158)
ExcelSheet.PageSetup.Zoom = 90
ExcelSheet.PageSetup.PaperSize = "xlPaperA4"
' defino ancho y alto de columnas y filas
ExcelSheet.Columns("A:A").ColumnWidth = 7
'ajusto celdas combinadas
ExcelSheet.Range("E2:H2").Merge
'ajusto sombreados color gris, celeste y naranja
ExcelSheet.Cells(7, 7).Interior.ColorIndex = 8
'ajusto alineación
ExcelSheet.Range("A8:L18").HorizontalAlignment = -4108
'coloco los bordes
ExcelSheet.Range("A1:L6").Borders(5).LineStyle = -4142
ExcelSheet.Range("A1:L6").Borders(6).LineStyle = -4142
ExcelSheet.Range("A1:L6").Borders(7).LineStyle = 1
ExcelSheet.Range("A1:L6").Borders(7).Weight = 4
ExcelSheet.Range("A1:L6").Borders(7).ColorIndex = -4105
ExcelSheet.Range("A1:L6").Borders(8).LineStyle = 1
ExcelSheet.Range("A1:L6").Borders(8).Weight = 4
ExcelSheet.Range("A1:L6").Borders(8).ColorIndex = -4105
ExcelSheet.Range("A1:L6").Borders(9).LineStyle = 1
ExcelSheet.Range("A1:L6").Borders(9).Weight = 4
ExcelSheet.Range("A1:L6").Borders(9).ColorIndex = -4105
ExcelSheet.Range("A1:L6").Borders(10).LineStyle = 1
ExcelSheet.Range("A1:L6").Borders(10).Weight = 4
ExcelSheet.Range("A1:L6").Borders(10).ColorIndex = -4105
ExcelSheet.Range("A1:L6").Borders(11).LineStyle = -4142
ExcelSheet.Range("A1:L6").Borders(12).LineStyle = -4142
'coloco el texto fijo
ExcelSheet.Range("A1:L59").Characters.Font.Name = "Arial"
ExcelSheet.Range("A19:L31").Characters.Font.size = 10
ExcelSheet.Cells(8, 1).Value = "Fecha de Emision"
'coloco imagenes
' ExcelSheet.Cells(4, 9).Value = Me.Image_TECNOGIS.Picture
'incorporacion de datos segun informe
ExcelSheet.Cells(8, 3).Value = DateTime.Date
ExcelSheet.Cells(8, 3).Characters.Font.FontStyle = "Negrita"
ExcelSheet.Cells(8, 3).Characters.Font.size = 8
ExcelSheet.Cells(9, 3).Value = InputBox("Ingrese el nombre del solicitante.", "Solicitante")
ExcelSheet.Cells(9, 3).Characters.Font.FontStyle = "Negrita"
ExcelSheet.Cells(9, 3).Characters.Font.size = 8
ExcelSheet.Cells(11, 3).Value = NoNulo(rsEnsayos("controladopor"))
ExcelSheet.Cells(11, 3).Characters.Font.FontStyle = "Negrita"
ExcelSheet.Cells(11, 3).Characters.Font.size = 8
ExcelSheet.Cells(10, 3).Value = NoNulo(rsEnsayos("fecha_control"))
ExcelSheet.Cells(10, 3).Characters.Font.FontStyle = "Negrita"
ExcelSheet.Cells(10, 3).Characters.Font.size = 8
'Ingreso datos del grafico
ExcelChart.ActiveChart.ChartType = xlXYScatterSmooth
ExcelChart.ActiveChart.SeriesCollection.NewSeries
ExcelChart.ActiveChart.SeriesCollection(1).XValues = "=Hoja1!R19C11:R31C11"
ExcelChart.ActiveChart.SeriesCollection(1).Values = "=Hoja1!R19C12:R31C12"
ExcelChart.ActiveChart.SeriesCollection(1).Name = "=""%E(NIram)"""
Windows("Libro4").SmallScroll Down:=16
ExcelChart.ActiveChart.Axes(xlValue).MajorGridlines.Select
With ExcelChart.ActiveChart.Axes(xlValue)
.MinimumScaleIsAuto = True
.MaximumScale = 15
.MinorUnit = 1
.MajorUnit = 5
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ExcelChart.ActiveChart.ChartArea.Select
With ExcelChart.ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "%INominal"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "%Errores"
End With
ExcelChart.ActiveChart.HasLegend = False
'' ExcelChart.ChartType = 72
'' ExcelChart.SeriesCollection.NewSeries
'' ExcelChart.SeriesCollection.NewSeries
'' ExcelChart.SeriesCollection.NewSeries
'' ExcelChart.SeriesCollection(1).XValues = "=Hoja1!K19:K31"
'' ExcelChart.SeriesCollection(1).Values = "=Hoja1!L19:L31"
'' ExcelChart.SeriesCollection(1).Name = "=%E(NIram)"
'' ExcelChart.SeriesCollection(2).XValues = "=Hoja1!E19:E31"
'' ExcelChart.SeriesCollection(2).Values = "=Hoja1!F19:F31"
'' ExcelChart.SeriesCollection(2).Name = "=%E(Sin Ajustar)"
'' ExcelChart.SeriesCollection(3).XValues = "=Hoja1!G19:G31"
'' ExcelChart.SeriesCollection(3).Values = "=Hoja1!G19:G31"
'' ExcelChart.SeriesCollection(3).Name = "=%E(Con Ajuste)"
''
'' ExcelChart.Location Where:=2, Name:="Hoja1"
''
'' ExcelChart.HasTitle = True
'' ExcelChart.ChartTitle.Characters.Text = "Cos Q=0.5"
''
'' ExcelChart.Axes(1, 2).HasTitle = True
'' ExcelChart.Axes(1, 1).AxisTitle.Characters.Text = "%I Nominal"
'' ExcelChart.Axes(2, 1).HasTitle = True
'' ExcelChart.Axes(2, 1).AxisTitle.Characters.Text = "% Errores"
''
'' ExcelChart.HasLegend = False
'' ExcelApp.Windows("Libro4").SmallScroll Down:=9
'' ExcelSheet.Shapes("Grafico 1").incementleft -181.5
'' ExcelSheet.Shapes("Grafico 1").incementtop 313.5
'' ExcelSheet.Shapes("Grafico 1").ScaleWidth 1.42, 0, 0
'' ExcelSheet.Shapes("Grafico 1").ScaleWidth 1#, 0, 2
'' ExcelSheet.Shapes("Grafico 1").ScaleHeight 0.72, 0, 0
''
'' ExcelChart.Axes(2).MajorGridlines.Select
''
'' ExcelChart.Axes(2).MinimumScaleIsAuto = True
'' ExcelChart.Axes(2).MaximumScale = 15
'' ExcelChart.Axes(2).MinorUnit = 1
'' ExcelChart.Axes(2).MajorUnit = 5
'' ExcelChart.Axes(2).Crosses = -4105
'' ExcelChart.Axes(2).ReversePlotOrder = False
'' ExcelChart.Axes(2).ScaleType = -4132
'' ExcelChart.Axes(2).DisplayUnit = -4142
''
''
ExcelApp.Visible = True
Dim ExcelApp As Object
Dim ExcelWorkbook As Object
Dim ExcelSheet As Object
Dim ExcelChart As Object
Dim ExcelChart2 As Object
Dim strsql As String
Dim s As Integer
Dim t As Integer
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelWorkbook = ExcelApp.Workbooks.Add 'Open(strGIS & " eportesMED-Ensayos.xls")
Set ExcelSheet = ExcelWorkbook.Worksheets(1)
Set ExcelChart = ExcelSheet.ChartObjects.Add(5, 440, 690, 150)
Set ExcelChart2 = ExcelSheet.ChartObjects.Add(5, 595, 690, 140)
'configuro la página
ExcelSheet.PageSetup.PrintTitleRows = ""
ExcelSheet.PageSetup.LeftMargin = ExcelApp.InchesToPoints(0.590661181102362)
ExcelSheet.PageSetup.RightMargin = ExcelApp.InchesToPoints(0.196850393700079)
ExcelSheet.PageSetup.TopMargin = ExcelApp.InchesToPoints(0.393700078740158)
ExcelSheet.PageSetup.BottomMargin = ExcelApp.InchesToPoints(0.393700078740158)
ExcelSheet.PageSetup.Zoom = 90
ExcelSheet.PageSetup.PaperSize = "xlPaperA4"
' defino ancho y alto de columnas y filas
ExcelSheet.Columns("A:A").ColumnWidth = 7
'ajusto celdas combinadas
ExcelSheet.Range("E2:H2").Merge
'ajusto sombreados color gris, celeste y naranja
ExcelSheet.Cells(7, 7).Interior.ColorIndex = 8
'ajusto alineación
ExcelSheet.Range("A8:L18").HorizontalAlignment = -4108
'coloco los bordes
ExcelSheet.Range("A1:L6").Borders(5).LineStyle = -4142
ExcelSheet.Range("A1:L6").Borders(6).LineStyle = -4142
ExcelSheet.Range("A1:L6").Borders(7).LineStyle = 1
ExcelSheet.Range("A1:L6").Borders(7).Weight = 4
ExcelSheet.Range("A1:L6").Borders(7).ColorIndex = -4105
ExcelSheet.Range("A1:L6").Borders(8).LineStyle = 1
ExcelSheet.Range("A1:L6").Borders(8).Weight = 4
ExcelSheet.Range("A1:L6").Borders(8).ColorIndex = -4105
ExcelSheet.Range("A1:L6").Borders(9).LineStyle = 1
ExcelSheet.Range("A1:L6").Borders(9).Weight = 4
ExcelSheet.Range("A1:L6").Borders(9).ColorIndex = -4105
ExcelSheet.Range("A1:L6").Borders(10).LineStyle = 1
ExcelSheet.Range("A1:L6").Borders(10).Weight = 4
ExcelSheet.Range("A1:L6").Borders(10).ColorIndex = -4105
ExcelSheet.Range("A1:L6").Borders(11).LineStyle = -4142
ExcelSheet.Range("A1:L6").Borders(12).LineStyle = -4142
'coloco el texto fijo
ExcelSheet.Range("A1:L59").Characters.Font.Name = "Arial"
ExcelSheet.Range("A19:L31").Characters.Font.size = 10
ExcelSheet.Cells(8, 1).Value = "Fecha de Emision"
'coloco imagenes
' ExcelSheet.Cells(4, 9).Value = Me.Image_TECNOGIS.Picture
'incorporacion de datos segun informe
ExcelSheet.Cells(8, 3).Value = DateTime.Date
ExcelSheet.Cells(8, 3).Characters.Font.FontStyle = "Negrita"
ExcelSheet.Cells(8, 3).Characters.Font.size = 8
ExcelSheet.Cells(9, 3).Value = InputBox("Ingrese el nombre del solicitante.", "Solicitante")
ExcelSheet.Cells(9, 3).Characters.Font.FontStyle = "Negrita"
ExcelSheet.Cells(9, 3).Characters.Font.size = 8
ExcelSheet.Cells(11, 3).Value = NoNulo(rsEnsayos("controladopor"))
ExcelSheet.Cells(11, 3).Characters.Font.FontStyle = "Negrita"
ExcelSheet.Cells(11, 3).Characters.Font.size = 8
ExcelSheet.Cells(10, 3).Value = NoNulo(rsEnsayos("fecha_control"))
ExcelSheet.Cells(10, 3).Characters.Font.FontStyle = "Negrita"
ExcelSheet.Cells(10, 3).Characters.Font.size = 8
'Ingreso datos del grafico
ExcelChart.ActiveChart.ChartType = xlXYScatterSmooth
ExcelChart.ActiveChart.SeriesCollection.NewSeries
ExcelChart.ActiveChart.SeriesCollection(1).XValues = "=Hoja1!R19C11:R31C11"
ExcelChart.ActiveChart.SeriesCollection(1).Values = "=Hoja1!R19C12:R31C12"
ExcelChart.ActiveChart.SeriesCollection(1).Name = "=""%E(NIram)"""
Windows("Libro4").SmallScroll Down:=16
ExcelChart.ActiveChart.Axes(xlValue).MajorGridlines.Select
With ExcelChart.ActiveChart.Axes(xlValue)
.MinimumScaleIsAuto = True
.MaximumScale = 15
.MinorUnit = 1
.MajorUnit = 5
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ExcelChart.ActiveChart.ChartArea.Select
With ExcelChart.ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "%INominal"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "%Errores"
End With
ExcelChart.ActiveChart.HasLegend = False
'' ExcelChart.ChartType = 72
'' ExcelChart.SeriesCollection.NewSeries
'' ExcelChart.SeriesCollection.NewSeries
'' ExcelChart.SeriesCollection.NewSeries
'' ExcelChart.SeriesCollection(1).XValues = "=Hoja1!K19:K31"
'' ExcelChart.SeriesCollection(1).Values = "=Hoja1!L19:L31"
'' ExcelChart.SeriesCollection(1).Name = "=%E(NIram)"
'' ExcelChart.SeriesCollection(2).XValues = "=Hoja1!E19:E31"
'' ExcelChart.SeriesCollection(2).Values = "=Hoja1!F19:F31"
'' ExcelChart.SeriesCollection(2).Name = "=%E(Sin Ajustar)"
'' ExcelChart.SeriesCollection(3).XValues = "=Hoja1!G19:G31"
'' ExcelChart.SeriesCollection(3).Values = "=Hoja1!G19:G31"
'' ExcelChart.SeriesCollection(3).Name = "=%E(Con Ajuste)"
''
'' ExcelChart.Location Where:=2, Name:="Hoja1"
''
'' ExcelChart.HasTitle = True
'' ExcelChart.ChartTitle.Characters.Text = "Cos Q=0.5"
''
'' ExcelChart.Axes(1, 2).HasTitle = True
'' ExcelChart.Axes(1, 1).AxisTitle.Characters.Text = "%I Nominal"
'' ExcelChart.Axes(2, 1).HasTitle = True
'' ExcelChart.Axes(2, 1).AxisTitle.Characters.Text = "% Errores"
''
'' ExcelChart.HasLegend = False
'' ExcelApp.Windows("Libro4").SmallScroll Down:=9
'' ExcelSheet.Shapes("Grafico 1").incementleft -181.5
'' ExcelSheet.Shapes("Grafico 1").incementtop 313.5
'' ExcelSheet.Shapes("Grafico 1").ScaleWidth 1.42, 0, 0
'' ExcelSheet.Shapes("Grafico 1").ScaleWidth 1#, 0, 2
'' ExcelSheet.Shapes("Grafico 1").ScaleHeight 0.72, 0, 0
''
'' ExcelChart.Axes(2).MajorGridlines.Select
''
'' ExcelChart.Axes(2).MinimumScaleIsAuto = True
'' ExcelChart.Axes(2).MaximumScale = 15
'' ExcelChart.Axes(2).MinorUnit = 1
'' ExcelChart.Axes(2).MajorUnit = 5
'' ExcelChart.Axes(2).Crosses = -4105
'' ExcelChart.Axes(2).ReversePlotOrder = False
'' ExcelChart.Axes(2).ScaleType = -4132
'' ExcelChart.Axes(2).DisplayUnit = -4142
''
''
ExcelApp.Visible = True
Valora esta pregunta


0