我需要知道如何使用VBA禁用单元格内容检测,因为当我从* .CSV文件导入数据时,我不想在"日期格式&#中获取日期34;即使我在导入时指定它只是文本。我想把日期作为字符串。如果我在导入后尝试更改格式,我会得到一个数字,而不是带有日期的字符串。
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
答案 0 :(得分: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