Visual Basic - Problema con fecha al exportar a Excel

Life is soft - evento anual de software empresarial
 
Vista:

Problema con fecha al exportar a Excel

Publicado por Macarena (1 intervención) el 29/01/2020 15:55:34
Buenos días, quería pedirles ayuda con VB6, específicamente con la exportación de datos a Excel, ya que al exportar, las columnas de fechas quedan con formato DD/MM/YYYY en el excel, pero al comparar el dato con lo que se encuentra en la grilla y en la base de datos están como MM/DD/YYYY, esto sucede con los días del 1 al 12, ya he probado de todo y no hay caso en que esto cambie, también otro detalle es que cuando pongo el método paste del objeto de Excel se exporta de esta manera pero al comentar esto y que quede "manual" osea apretando el "CTRL + V" se exporta todo bien.

Ayudaaaa!!!

Adjunto el código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
Function Exportar_Spread_Excel(oSpread As vaSpread, Optional bWithHead As Boolean = False, Optional bAllColumns As Boolean = True, Optional bExcel_is_Closed As Boolean = True, Optional Excel As Object, Optional ExcelWBk As Excel.Workbook, Optional ExcelWS As Excel.Worksheet, Optional DesdeFila As Integer = 0)
 
Dim iMouse%, iCol%, sCol$, iRows&, I%
 
Dim CeldaPaste$, sfmt$
 
On Local Error GoTo Error_Excel
 
iMouse% = Screen.MousePointer
 
Screen.MousePointer = 11
 
Call Globales.Barra_Progreso(0, True)
 
Call Globales.Barra_Progreso(oSpread.MaxCols + 10, False)
 
If bExcel_is_Closed Then
 
Set Excel = CreateObject("Excel.Application") 'Create Excel Object.
 
Set ExcelWBk = Excel.Workbooks.Add 'Add this Workbook to Excel.
 
Set ExcelWS = ExcelWBk.Worksheets(1) ' Add this sheet to this Workbook
 
End If
 
'-- Copiando a portapapeles
 
Call Globales.Barra_Progreso(1)
 
Clipboard.Clear
 
oSpread.Row = 1
 
oSpread.Col = 1
 
oSpread.Row2 = oSpread.MaxRows
 
oSpread.Col2 = oSpread.MaxCols
 
Clipboard.SetText oSpread.Clip
 
'-- formateo Worksheet todo como Texto
 
Call Globales.Barra_Progreso(2)
 
' ExcelWS.Cells.Select
 
' ExcelWS.Cells.NumberFormat = "general"
 
' ExcelWS.Cells.NumberFormatLocal = "@"
 
'-- Copiando a Excel
 
Call Globales.Barra_Progreso(3)
 
ExcelWS.Columns("L:L").NumberFormatLocal = "dd/mm/yyyy"
 
ExcelWS.Range("M:M").NumberFormatLocal = "dd/mm/yyyy"
 
ExcelWS.Range("N:N").NumberFormatLocal = "dd/mm/yyyy"
 
CeldaPaste = "A" & CStr((1 + DesdeFila))
 
ExcelWS.Range(CeldaPaste).Select
 
ExcelWS.Paste
 
iRows = oSpread.MaxRows + DesdeFila + 5
 
'iRows = oSpread.MaxRows
 
For iCol = oSpread.MaxCols To 1 Step -1
 
Call Globales.Barra_Progreso(4)
 
'-- columna
 
oSpread.Col = iCol
 
sCol = ""
 
If iCol > 26 Then
 
sCol = Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Val(Left(CStr((iCol - 1) / 26), 1)), 1)
 
iCol = iCol - (Val(Left(CStr((iCol - 1) / 26), 1)) * 26)
 
End If
 
sCol = sCol & Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", iCol, 1)
 
'Debug.Print iCol & vbTab & " -> " & sCol
 
iCol = oSpread.Col
 
'-- rango
 
CeldaPaste = sCol & CStr(2 + DesdeFila) & ":" & sCol & CStr(iRows)
 
'-- control
 
If oSpread.ColHidden And Not bAllColumns Then
 
ExcelWS.Columns(sCol & ":" & sCol).Delete
 
' ElseIf oSpread.CellType = CellTypeCurrency Or oSpread.CellType = CellTypeNumber Or oSpread.CellType = CellTypePercent Then
 
' If Not ExcelWS.Range(CeldaPaste).Find(".") Is Nothing Then
 
' ExcelWS.Range(CeldaPaste).Replace ".", ""
 
' End If
 
' If Not ExcelWS.Range(CeldaPaste).Find(".") Is Nothing Then
 
' ExcelWS.Range(CeldaPaste).Replace ",", "."
 
' End If
 
' For I = 0 To 9
 
' If Not ExcelWS.Range(CeldaPaste).Find(CStr(I)) Is Nothing Then
 
' ExcelWS.Range(CeldaPaste).Replace CStr(I), CStr(I)
 
' End If
 
' Next I
 
' If oSpread.CellType = CellTypeCurrency Then
 
' sfmt$ = String(oSpread.TypeCurrencyDecPlaces, "0")
 
' ElseIf oSpread.CellType = CellTypePercent Then
 
' sfmt$ = String(oSpread.TypePercentDecPlaces, "0")
 
' Else
 
' sfmt$ = String(oSpread.TypeNumberDecPlaces, "0")
 
' End If
 
' If sfmt$ = "" Then
 
' sfmt$ = "#.##0"
 
' Else
 
' sfmt$ = "#.##0," & sfmt$
 
' End If
 
' ExcelWS.Columns(sCol & ":" & sCol).NumberFormatLocal = sfmt$ & ";[Rojo]-" & sfmt$
 
'
 
' ElseIf oSpread.CellType = CellTypeDate Then
 
' ExcelWS.Columns(sCol & ":" & sCol).NumberFormatLocal = "dd/mm/yyyy"
 
'
 
' ElseIf oSpread.CellType = CellTypeStaticText Then
 
' sCol = sCol & ":" & sCol
 
' ExcelWS.Columns(sCol).NumberFormat = "General"
 
' ExcelWS.Columns(sCol).HorizontalAlignment = xlGeneral
 
' ExcelWS.Columns(sCol).VerticalAlignment = xlTop
 
' ExcelWS.Columns(sCol).WrapText = False
 
' ExcelWS.Columns(sCol).Orientation = 0
 
' ExcelWS.Columns(sCol).AddIndent = False
 
' ExcelWS.Columns(sCol).IndentLevel = 0
 
' ExcelWS.Columns(sCol).ShrinkToFit = False
 
' ExcelWS.Columns(sCol).ReadingOrder = xlContext
 
' ExcelWS.Columns(sCol).MergeCells = False
 
'
 
' End If
 
'-- Ajusta columnas muy anchas '-- 2009.06.03
 
ExcelWS.Columns(sCol).EntireColumn.AutoFit
 
'Debug.Print ExcelWS.Columns(sCol).ColumnWidth
 
If ExcelWS.Columns(sCol).ColumnWidth > 50 Then
 
ExcelWS.Columns(sCol).ColumnWidth = 50
 
End If
 
'iRows = iRows - 1
 
Next iCol
 
ExcelWS.Cells.Select
 
ExcelWS.Cells.EntireRow.AutoFit
 
ExcelWS.Range("A1").Select
 
'oSpread.ClearSelection
 
Excel.Visible = True
 
'SendKeys "^(v)", True
 
If bExcel_is_Closed Then
 
Set ExcelWS = Nothing
 
'Excel.Quit
 
Set ExcelWBk = Nothing
 
Set Excel = Nothing
 
End If
 
Screen.MousePointer = iMouse%
 
GoTo fin
 
Error_Excel:
 
MsgBox "Error al intentar exportar a Excel" & vbCrLf & vbCrLf & Err.Description & " Code:" & Err.Number, vbExclamation, "Exportando datos a Excel"
 
Screen.MousePointer = iMouse%
 
fin:
 
Call Globales.Barra_Progreso(6)
 
Beep
 
Call Globales.Barra_Progreso(10, True)
 
End Function
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Aslén
Val: 3
Ha aumentado su posición en 2 puestos en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Problema con fecha al exportar a Excel

Publicado por Aslén (2 intervenciones) el 06/02/2020 13:44:57
Tengo el mismo problema con el formato de fecha en Visual Studio 2012 , alguien me puede ayudar?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar