Private Sub Command1_Click()
Dim xlsApp As Variant
'Dim xlsApp As Excel.Application
'Set xlsApp = Excel.Application
Set xlsApp = CreateObject("Excel.application")
With xlsApp 'ApExcel
.Visible = True
.Workbooks.Add
men = "titulo" & vbCrLf & "Estudio de Rendimiento"
.Cells(1, 1) = Text1.Text
.Cells(1, 1).Font.Size = 12
'.Cell(1, 1).Font.FontStyle = "Verdana"
.Cells(1, 1).Font.Bold = True
.Range("A1").Select
.Selection.HorizontalAlignment = 3 'Center=3, Left=1 2, Right=4
.Cells(3, 1) = Text2.Text
.Cells(3, 1).Font.Size = 10
.Cells(3, 1).Font.Bold = True
.Range("A3").Select
.Selection.HorizontalAlignment = 3
For f = 0 To msflex.Rows - 1
For h = 0 To msflex.Cols - 1
With msflex
'.Col = h .Row = f
m = .TextMatrix(f, h)
End With
.Cells(5 + f, 1 + h) = m
Next h
b = "A" & 5 + f
b1 = "D" & 5 + f
.Range(b & ":" & b1).Borders.Color = RGB(0, 0, 0)
.Range(b & ":" & b1).Borders.LineStyle = 1 'Hasta el 12
Next f
'En negrita titulos de las columnas
.Range(A & 5 & ":" & D & 5).Select
.Selection.Font.Bold = True
'Alinear contenido primera tabla
For al1 = 0 To msflex.Rows
b = "A" & 5 + al1
b1 = "D" & 5 + al1
'.Range(b & ":" & b1).Borders.Color = RGB(0, 0, 0)
.Range(b & ":" & b1).Select
.Selection.HorizontalAlignment = 3
Next al1
.Cells(5 + msflex.Rows + 1, 1) = "Continuación Segunda Tabla"
For n = 0 To msflex1.Rows - 1
For m = 0 To msflex1.Cols - 1
With msflex1
'.Col = m .Row = n
l = .TextMatrix(n, m)
End With
.Cells(5 + n + msflex.Rows + 3, 1 + m) = l
Next m
b = "A" & 5 + n + msflex.Row + 3 + 1
b1 = "E" & 5 + n + msflex.Row + 3 + 1
.Range(b & ":" & b1).Borders.Color = RGB(0, 0, 0)
.Range(b & ":" & b1).Borders.LineStyle = 1
Next n
'En negrita titulos de ls segunda tabla
.Range(A & 5 + msflex.Row + 4 & ":" & D & 5 + msflex.Row + 4).Select
.Selection.Font.Bold = True
'Alinear toda la segunda tabla
For al = 0 To msflex1.Rows
b = "A" & 5 + al + msflex.Row + 3
b1 = "E" & 5 + al + msflex.Row + 3
.Range(b & ":" & b1).Select
.Selection.HorizontalAlignment = 3
Next al
'Continuación de los textos
.Cells(5 + msflex1.Row + msflex.Row + 6, 1) = "Resto del texto"
b = "A" & 5 + msflex1.Row + msflex.Row + 6
.Range(b).Select
.Selection.Font.Bold = True
'Seleccionar última celda
b = "A" & 5 + msflex1.Row + msflex.Row + 8
.Range(b).Select
.Sheets("Hoja1").Name = "Inventario"
'Ver documento antes de imprimir
If optVista.Value = True Then
.Worksheets.PrintPreview
End If
Set ApExcel = Nothing
End With
End Sub