Thread: Dates import
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
rmcsantos rmcsantos is offline
external usenet poster
 
Posts: 4
Default Dates import

I import the file, by an macro.
++++
Private Sub import_ficheiro_Click()
Dim fs, a As Object
Dim linha(23), linha_lida(23, 8), mystring, historico_caminho_destino,
origem_caminho As String
Dim timedate As Date
Dim filetoopen As Variant
Dim i, caracter, col_escrita, rwindex, colindex, linha_disp, linha_escr As
Integer
historico_caminho_destino = "\\anubis\Users\TimeSheet\history\"
origem_caminho = "\\anubis\Users\TimeSheet"
filetoopen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If filetoopen = False Then
Exit Sub
End If
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile(filetoopen, 1)
For i = 1 To 23
linha(i) = a.readline
Next i
timedate = Left(Right(filetoopen, 14), 10)
If linha(1) = "Ja Importado" Then
MsgBox "Ficheiro já importado!"
a.Close
Exit Sub
End If
col_escrita = 1
linha_disp = Worksheets("BD_horas").Range("linha_disp").Value
For i = 1 To 23
col_escrita = 1
For caracter = 1 To Len(linha(i))
mystring = Mid(linha(i), caracter, 1)
If mystring < ";" Then
linha_lida(i, 1) = linha_lida(i, 1) & mystring
Else
If col_escrita < 1 Then
Else
If linha_disp = 1 Or i = 1 Then
linha_disp = linha_disp + 1
End If
linha_escr = i + linha_disp
If i = 3 Then
linha_escr = linha_escr - i + 2
End If
End If
If col_escrita = 6 Then
If linha_lida(i, 1) = "" Then
Exit For
Else
linha_lida(i, 1) = linha_lida(i, 1) / 1
End If
End If
Worksheets("BD_Horas").Cells(linha_escr, col_escrita).Value =
linha_lida(i, 1)
linha_lida(i, 1) = ""
col_escrita = col_escrita + 1
linha_disp = Worksheets("BD_horas").Range("linha_disp").Value
End If
Next caracter
If linha_disp = 1 Or i = 1 Then
Worksheets("BD_Horas").Cells(linha_escr, 8).Value = timedate
Else
Worksheets("BD_Horas").Cells(linha_escr - 1, 8).Value = timedate
End If
Next i
a.Close
Set fs = CreateObject("Scripting.FileSystemObject")
fs.movefile filetoopen, historico_caminho_destino
End Sub
++++


--
Rui Santos


"Miguel Zapico" wrote:

If you use the wizard to open/import the text file, on the last screen you
can go field by field selecting basic formating options. You can select you
date fields, and mark if you want them imported as MDY or DMY.

Hope this helps,
Miguel.

"rmcsantos" wrote:

i have 2 files, one create a txt file, and export a cell value with a date.
6-12-2006
The second file import txt file, and read the date field, and change
12-6-2006.

How can resolve this question?

Thank you in advance.
--
Rui Santos