Enviar el BackColor de un MSFlexGrid a Excel

Estoy trabajando en Visual 6.0, tengo un MsflexGrid el cual al darle click en cualquier Celda a alguno de los registros que tiene el Grid cambia de color, pero cuando envío esos datos a Excel, no me manda el color de la celda que había seleccionado,... ¿cómo puedo hacer para que cuando envío los datos a excel me respete el color que yo había cambiado en el Grid?
Te agradecería mucho si me Ayudaras!
Te anexo el código donde le doy click a una celda del Grid y cambia de color:
Private Sub MSFlexGrid1_Click()
MSFlexGrid1.RowSel = MSFlexGrid1.Row
If MSFlexGrid1.Col < 2 Then Exit Sub
If MSFlexGrid1.CellBackColor = 0 Then
MSFlexGrid1.CellBackColor = vbGreen
Else
MSFlexGrid1.CellBackColor = 0
End If
End Sub
y este es el codigo del boton al enviar a Excel:
If CmbLineas.ListIndex >= 0 Then
Funciones.EnviarDatosExcel2
End If
Esta es la Funcion:
Dim ProgramaXLS As Excel.Application
Dim Libro As Excel.Workbook
Dim Hoja As Excel.Worksheet
Dim qTbl As QueryTable
Dim strSql As String
Dim fila As Integer
Dim columna As Integer
'Dim FlexGrid As MSFlexGrid
EnviarDatosExcel2 = False
Set ProgramaXLS = Excel.Application
Set Libro = ProgramaXLS.Workbooks.Add
Set Hoja = Libro.Worksheets(1)
'strSql = "SELECT L.Lineas, M.Maquinas FROM Maquinas M " & _
'"INNER JOIN Lineas L ON M.IDlineas = L.IDlineas "
' If Linea > 0 Then strSql = strSql & "WHERE L.IDlineas = " & Linea
ProgramaXLS.Visible = False
With Hoja
.Cells(1, 1).Font.Size = 5
.Cells(1, 1).Font.Bold = False
.Cells(1, 1).Font.ColorIndex = 1
.Cells(2, 1) = "Calendario Anual de Mantenimiento Preventivo, Año 2009"
'.Cells(2, 1).Font.Bold = True
.Cells(2, 1).Font.Size = 14
.Cells(2, 1).Font.Bold = True
.Cells(2, 1).Font.ColorIndex = 1
.Cells(6, 1).Interior.ColorIndex = 37
.Cells(6, 2).Interior.ColorIndex = 6
.Cells(6, 3).Interior.ColorIndex = 37
.Cells(6, 4).Interior.ColorIndex = 6
.Cells(6, 5).Interior.ColorIndex = 6
.Cells(6, 6).Interior.ColorIndex = 6
.Cells(6, 7).Interior.ColorIndex = 6
.Cells(6, 8).Interior.ColorIndex = 6
.Cells(6, 9).Interior.ColorIndex = 6
.Cells(6, 10).Interior.ColorIndex = 6
.Cells(6, 11).Interior.ColorIndex = 6
Range("A2", "G5").Merge
Range("A7", "G7").Select
Range("I1", "I1").Select
'ActiveWindow.FreezePanes = True
'Range("H1", "A1").Font.Size = 14
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Dim i As Integer, j As Integer
For i = 0 To Form1.MSFlexGrid1.Cols - 1
For j = Form1.MSFlexGrid1.FixedRows To Form1.MSFlexGrid1.Rows - (Form1.MSFlexGrid1.FixedRows)
Form1.MSFlexGrid1.Col = i: Form1.MSFlexGrid1.Row = j
Hoja.Cells(j + 7, i + 1) = Form1.MSFlexGrid1.TextMatrix(j, i)
Next j
Next i
ProgramaXLS.Visible = True

1 respuesta

Respuesta
1
Disculpa la demora que acabo de conectarme, te doy una solución que no es muy complicada:
Bueno donde tienes los for para enviar los datos al excel:
Dim i As Integer, j As Integer
For i = 0 To MSFlexGrid1.Cols - 1
For j = MSFlexGrid1.FixedRows To MSFlexGrid1.Rows - (MSFlexGrid1.FixedRows)
MSFlexGrid1.Col = i
MSFlexGrid1.Row = j
Hoja.Cells(j + 7, i + 1) = MSFlexGrid1.TextMatrix(j, i)
' Le agregamos un if que ve si la celda esta en verde
If MSFlexGrid1.CellBackColor = vbGreen Then
   Hoja.Cells(j + 7, i + 1).Interior.Color = vbGreen ' Si se cumple pone la celda correspondiente (del excel) en verde.
Else
   ' Si no se cumple la deja en blanco.
   Hoja.Cells(j + 7, i + 1).Interior.Color = vbWhite
End If
Hoja.Cells(j + 7, i + 1).Borders.Color = &HC0C0C0 ' Aca dejamos el color de las lineas de las celdas con su color correspondiente (si esto no se hace las lineas quedan en blanco y se ve un poco mal)
Next j
Next i
ProgramaXLS.Visible = True
Set ProgramaXLS = Nothing ' Recuerda poner esto al final para que se descarge la aplicacion de memoria al final.
Espero y te sea de ayuda.
Cualquier duda me dices.
Bye.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas