
21/09/2007, 21:25
|
 | | | Fecha de Ingreso: septiembre-2007
Mensajes: 154
Antigüedad: 17 años, 7 meses Puntos: 29 | |
Problemas Con Fecha Al Exportar Desde Vb A Excel TENGO ESTE CODIGO PAR EXPORTAR DATOS A EXCEL DESDE VB
Public Sub ExportarGrid(Grid As MSHFlexGrid, FileName As String, FileType)
Dim i As Long
Dim j As Long
Dim variable As String
On Error GoTo ErrHandler
'Let's put a HourGlass pointer for the mouse
Screen.MousePointer = vbHourglass
If FileType = 1 Then 'Export to excel
'Gimme the workbook
Dim wkbNew As Excel.Workbook
'Gimme the worksheet for the workbook
Dim wkbSheet As Excel.Worksheet
'Gimme the range for the worksheet
Dim Rng As Excel.Range
'Does the file exist?
If Dir(FileName) <> "" Then
'Kill it boy!
Kill FileName
End If
On Error GoTo CreateNew_Err
'Let's create the workbook kid!
Set wkbNew = Workbooks.Add
wkbNew.SaveAs FileName
'Add a WorkPage
Set wkbSheet = wkbNew.Worksheets(1)
'Set the values in the range
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
'Close and save the file
wkbNew.Close True
GoTo NoErrors
CreateNew_Err:
'Stop the show!
wkbNew.Close False
Set wkbNew = Nothing
Resume ErrHandler
Else 'Export to text
Dim Fs As Variant
Dim a As Variant
'I know, the File # sounds smarter, but, I like weird things :) !
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
If IsDate(DataGrid1.Item(fila, Columna).ToString) Then
variable = Convert.ToString(Microsoft.VisualBasic.Format(Data Grid1.Item(fila, Columna), "dd/MM/aaaa"))
End If
NoErrors:
'Gimme the default mouse pointer dude!
Screen.MousePointer = vbDefault
MsgBox "File has been saved", vbOKOnly, "Finished"
Exit Sub
ErrHandler:
'Gimme the default mouse pointer dude!
Screen.MousePointer = vbDefault
MsgBox "¡Vaya! ¡No puedo exportar el fichero!", vbOKOnly, "Error"
Exit Sub
End Sub
EL PROBLEMA ESTA EN QUE TENGO UN CAMPO FECHA EN MI TABLA Y ME LA MODIFICA CAMBIANDO 08/09/2007 X 09/08/2007 NO DOY CON QUE PUEDE SER ALGUNA IDEA PLEASE |