
Diegodcr
-
Posts
89 -
Cadastrado em
-
Última visita
Tópicos solucionados
-
O post de Diegodcr em Importar txt respeitando valor célula foi marcado como solução
@Edson Luiz Branco Na verdade eu tive que tratar de forma diferente, célula por célula pois o código que você citou acima, não funcionava.
Option Explicit Sub test() Dim fullName As String fullName = "c:\users\domenic\desktop\sample.txt" Dim columnCount As Long columnCount = GetColumnCountFromTextFile(fullName, vbTab) If columnCount = 0 Then MsgBox "No data found!", vbExclamation Exit Sub End If Workbooks.OpenText _ Filename:=fullName, _ DataType:=xlDelimited, _ Tab:=True, _ FieldInfo:=GetFieldInfo(columnCount) End Sub Private Function GetColumnCountFromTextFile(ByVal PathAndFilename As String, Optional ByVal Delim As String = ",") As Long ' Returns the number of columns contains in a text file ' First non-blank line used to determine number of columns based on delimiter Dim textLine As String Dim fileNumber As Long Dim columnCount As Long columnCount = 0 fileNumber = FreeFile() Open PathAndFilename For Input As #fileNumber Do Until EOF(fileNumber) Line Input #fileNumber, textLine If Len(textLine) > 0 Then columnCount = UBound(Split(textLine, Delim)) + 1 Exit Do End If Loop Close #fileNumber GetColumnCountFromTextFile = columnCount End Function Private Function GetFieldInfo(ByVal columnCount As Long) As Variant ' Returns a two-dimensional array containing a column number and data type pair ' Sets all columns to text format ReDim fieldInfoArray(1 To columnCount, 1 To 2) Dim i As Long For i = LBound(fieldInfoArray, 1) To UBound(fieldInfoArray, 1) fieldInfoArray(i, 1) = i fieldInfoArray(i, 2) = xlTextFormat Next i GetFieldInfo = fieldInfoArray() End Function
-
O post de Diegodcr em Captura de dados em pasta com condição foi marcado como solução
Pode fechar moderador
Sobre o Clube do Hardware
No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais
Direitos autorais
Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais