2014-11-05 6 views
0

* .CSV 파일에서 데이터를 가져올 때 "날짜 형식"으로 된 날짜를 가져 오지 않기 때문에 VBA를 사용하여 셀 내용 검색을 사용하지 않도록 설정하는 방법을 알아야합니다. 만약 내가 그것을 가져올 때 텍스트입니다 지정합니다. Dates를 String으로하고 싶습니다. 가져온 후에 형식을 변경하려고하면 날짜가있는 문자열 대신 숫자가 표시됩니다.vba를 사용하여 셀 내용 감지 사용 안 함

Cells.Select 
Selection.NumberFormat = "@" 

'importo los datos 
With ActiveSheet.QueryTables.Add(Connection:=datosConexion, Destination:=Range("$A$1")) 
    .name = archivo 
    .FieldNames = True 
    .RowNumbers = False 
    .FillAdjacentFormulas = False 
    .PreserveFormatting = True 
    .RefreshOnFileOpen = False 
    .RefreshStyle = xlInsertDeleteCells 
    .SavePassword = False 
    .SaveData = True 
    .AdjustColumnWidth = True 
    .RefreshPeriod = 0 
    .TextFilePromptOnRefresh = False 
    .TextFilePlatform = 65001 
    .TextFileStartRow = 1 
    .TextFileParseType = xlDelimited 
    .TextFileTextQualifier = xlTextQualifierDoubleQuote 
    .TextFileConsecutiveDelimiter = False 
    .TextFileTabDelimiter = False 
    .TextFileSemicolonDelimiter = False 
    .TextFileCommaDelimiter = True 
    .TextFileSpaceDelimiter = False 
    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _ 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1) 
    .TextFileDecimalSeparator = "." 
    .TextFileThousandsSeparator = "," 
    .TextFileTrailingMinusNumbers = True 
    .Refresh BackgroundQuery:=False 
End With 
+1

방법 각 문자열의 시작 부분에 아포스트로피를 추가하는 것에 대해? '' ' "& string' – kaybee99

+0

그 코드로 어떻게 할 수 있습니까? 왜냐하면 나는 행별로 * .csv 파일을 읽지 않기 때문이다. 방금 매크로를 기록하고 필요한 코드를 변경하여 코드를 사용했습니다. @ kaybee99 ?? – Carol

답변

1

당신은 변경해야합니다 : 당신이 텍스트로 가져올 필요가 날짜를 포함하는 열 (들)에 대한

.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _ 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1) 

1와 xlTextFormat 교체

+0

xlTextFormat에 대해 "1"을 모두 바꿀 수 있습니까? 텍스트가 필요합니다. – Carol

+0

데이터를 보지 않고도 확실한 대답을 드릴 수는 없습니다. ** VBA 백업 및 시도 ** –

+0

그것은 나를 위해 일했습니다! 감사합니다 @ 게리의 학생 – Carol