Problemas para exportar a Excel Hola a todos, tengo una consulta, lo que pasa es tengo una funcion para exportar mis archivos de un MshFlexgrid a Excel, el problema es que cuando exporto 56 columnas me sale el error.
aqui mando el codigo haber si alguien puede ayudarme.
Gracias de antemano
Public Sub ExportarGrid(Grid As MSHFlexGrid, FileName As String, FileType)
Dim I As Long
Dim J As Long
On Error GoTo ErrHandler
Screen.MousePointer = vbHourglass
If FileType = 1 Then 'Exportar a Excel
Dim wkbNew As Excel.Workbook
Dim wkbSheet As Excel.Worksheet
Dim Rng As Excel.Range
If Dir(FileName) <> "" Then
Kill FileName
End If
On Error GoTo CreateNew_Err
Set wkbNew = Workbooks.Add
wkbNew.SaveAs FileName
Set wkbSheet = wkbNew.Worksheets(1)
Set Rng = wkbSheet.Range("A1:" + Chr(Grid.Cols + 64) + CStr(Grid.Rows))
For J = 0 To Grid.Cols - 1
For I = 0 To Grid.Rows - 1
Rng.Range(Chr(J + 1 + 64) + CStr(I + 1)) = Grid.TextMatrix(I, J)
Next
Next
wkbNew.Close True
GoTo NoErrors
CreateNew_Err:
wkbNew.Close False
Set wkbNew = Nothing
Resume ErrHandler
Else
Dim Fs As Variant
Dim a As Variant
On Error GoTo ErrHandler
Set Fs = CreateObject("Scripting.FileSystemObject")
Set a = Fs.CreateTextFile(FileName, True)
Dim Line As String
For J = 0 To Grid.Rows - 1
For I = 0 To Grid.Cols - 1
Line = Line + Grid.TextMatrix(I, J) + vbTab
Next
a.WriteLine (Line)
Line = ""
Next
a.Close
End If
NoErrors:
Screen.MousePointer = vbDefault
MsgBox "El archivo ha sido guardado satisfactoriamente.", vbOKOnly, "Grabación Finalizada ..."
Exit Sub
ErrHandler:
Screen.MousePointer = vbDefault
MsgBox "No puedo exportar el fichero, Porfavor reinice el programa y vuelva a intentarlo.", vbOKOnly, "Sis - Error"
Exit Sub
End Sub |