Problemas con excel y vb6.0

Hola buen día a todos:

Tengo el siguiente problema con vb 6 y excel,

Tengo una aplicación en la cual mando un grid a excel con un formato definido, cuando corre la aplicación el excel despliega muy bien la información y el formato es como se diseño. Cuando corro la segunda vez el formato no se ejecuta como en la primera vez y aparte dentro del administrador de tarea existe una instacnia de excel activada.

Les coloco el código para ver si alguien me puede ayudar.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Add

For I = 1 To MSHImprime.Rows - 1
MSHImprime.Row = I
For j = 1 To MSHImprime.Cols - 1
MSHImprime.Col = j
objWorkbook.ActiveSheet.Cells(I + 1, j + 1).Value = MSHImprime.Text
Next
Next
objExcel.Rows("1:6").Select
objExcel.Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

objExcel.Range("a1:F51").Select
ActiveWindow.SmallScroll Down:=-27
With Selection.Font
.Name = "Arial"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With

objExcel.Columns("B:B").ColumnWidth = 18

'bordes
objExcel.Range("B8:D13").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
objExcel.Range("B16:D20").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
'cabeceras de color
objExcel.Range("B8:D8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 1216511
.TintAndShade = 0
.PatternTintAndShade = 0
End With
objExcel.Range("B16:D16").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 1216511
.TintAndShade = 0
.PatternTintAndShade = 0
End With


objExcel.Visible = True

Set objWorkbook = Nothing
Set objExcel = Nothing
Set ActiveSheet = Nothing

Añade tu respuesta

Haz clic para o