|
|
楼主 |
发表于 2010-12-31 11:10:26
|
显示全部楼层
谢谢二位回复,手动打开csv文件日期是没有问题的,单元格的格式不能设为text,我需要将csv文件粘到一个excel模板,这个模板里需要根据日期来查找对应日期的其它单元格值。我用FormatDateTime函数处理一下可以矫正日期格式,但我的文件太多且每个文件里有几百行,处理完所有的需要很长时间,我考虑将打开csv文件用ecel>datea>from text导入同时录制宏,然后用VBS调用该VBA或把VBA转换成VBS来实现,不熟悉VBA的操作还在研究中,有熟悉的帮忙看看,谢谢!
以下是录制的VBA代码:
Sub Macro1()
'
' Macro1 Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;D:\dstat.csv" _
, Destination:=Range("$A$1"))
.Name = "dstat"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub |
|