Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Ler arquivo txt e colocar no excel...
Estou usando a seguinte estrutura
Private Sub Command1_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim i As Long
Dim linha As String
' abrindo excel
Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.Workbooks.Add
'1 planilha 1(plan1)
Set xlsheet = xlbook.Worksheets(1)
xlapp.Visible = True
'abrindo arquivo texto
Open txttexto.Text For Input As #1
i = 2
topo = 1
'xlsheet.Range("a" & CStr(i)).Value = Mid(linha, 1, 5)
xlsheet.Range("a" & CStr(topo)).Value = "Current Data"
xlsheet.Range("b" & CStr(topo)).Value = "Current Time"
xlsheet.Range("c" & CStr(topo)).Value = "Number of licensed users specified by the configuration file"
xlsheet.Range("d" & CStr(topo)).Value = "Current number of total connections"
xlsheet.Range("e" & CStr(topo)).Value = "Maximum number of total connections"
xlsheet.Range("f" & CStr(topo)).Value = "Minimum number of total connections"
xlsheet.Range("g" & CStr(topo)).Value = "Current number of interactive connections"
xlsheet.Range("h" & CStr(topo)).Value = "Maximum number of interactive connections for the last hour"
xlsheet.Range("i" & CStr(topo)).Value = "Minimum number of interactive connections for the past hour"
xlsheet.Range("j" & CStr(topo)).Value = "Current number of batch connections"
xlsheet.Range("k" & CStr(topo)).Value = "Maximum number of batch connections for the past hour"
xlsheet.Range("l" & CStr(topo)).Value = "Minimum number of batch connections for the past hour"
Do While Not EOF(1)
Line Input #1, linha
xlsheet.Range("a" & CStr(i)).Value = Mid(linha, 1, 8)
xlsheet.Range("b" & CStr(i)).Value = Mid(linha, 11, 8)
xlsheet.Range("c" & CStr(i)).Value = Mid(linha, 21, 1)
xlsheet.Range("d" & CStr(i)).Value = Mid(linha, 23, 1)
xlsheet.Range("e" & CStr(i)).Value = Mid(linha, 25, 1)
xlsheet.Range("f" & CStr(i)).Value = Mid(linha, 27, 1)
xlsheet.Range("g" & CStr(i)).Value = Mid(linha, 29, 1)
xlsheet.Range("h" & CStr(i)).Value = Mid(linha, 31, 1)
xlsheet.Range("i" & CStr(i)).Value = Mid(linha, 33, 1)
xlsheet.Range("j" & CStr(i)).Value = Mid(linha, 35, 1)
xlsheet.Range("k" & CStr(i)).Value = Mid(linha, 37, 1)
xlsheet.Range("l" & CStr(i)).Value = Mid(linha, 39, 1)
i = i + 1
Loop
End Sub
Porém dessa forma ele pegas os campos com o mid, o problema é que tem valores que nao são fixos e estão separados por espaço, inclusive no começo ele separa por dois...
O arquivo esta vindo assim
04/05/11 01:00:00 5 3 4 0 3 4 0 0 0 004/05/11 02:00:00 5 3 36 3 3 3 3 0 0 004/05/11 03:00:00 5 3 3 83 3 3 3 80 0 004/05/11 04:00:00 5 3 3 33 3 3 3 0 0 004/05/11 05:00:00 5 3 3 3 63 3 3 0 0 004/05/11 06:00:00 5 3 3 83 3 3 3 0 0 004/05/11 07:00:00 5 3 3 3 3 3 3 0 0 0
O que fazer :(
Carregando comentários...