[英]Opening CSV files via Excel vba - date format change
There are multiple questions concerning this problem already however none of the answers seem to solve the problem for me. 关于这个问题已经有多个问题,但是似乎没有答案可以为我解决问题。 The problem is this: I am having to edit a large number of .csv files so am doing this via Excel VBA. 问题是这样的:我必须编辑大量的.csv文件,所以要通过Excel VBA进行此操作。 The first three columns are dates in format dd/mm/yyyy hh:mm:ss and these dates are converted to the US format MDY when opening via 前三列是以dd / mm / yyyy hh:mm:ss格式显示的日期,通过以下方式打开时,这些日期将转换为美国格式MDY。
set wb1 = Workbooks.Open (Filename:=savefolder & filename, Local:=True)
The most common answer for resolving this issue surrounds the known 'feature' that Excel will open CSV with the US dateformat unless the regional settings are used via the Local:=True but I have done this and it is still not working. 解决此问题的最常见答案围绕着已知的“功能”,即除非通过Local:= True使用区域设置,否则Excel将使用美国日期格式打开CSV,但我已经做到了,但仍然无法正常工作。 Can anyone advise of a setting that might need changing to get the following code to work? 谁能建议一个可能需要更改才能使以下代码正常工作的设置? thanks. 谢谢。
Sub cleandata()
dim wb1 as workbook
dim ws1 as worksheet
dim savefolder, filename as string
savefolder = "C:\Users\ME\Desktop\Clean Up Folder\"
filename = dir(savefolder & "*")
Do while len(filename) >0
set wb1 = Workbooks.Open (Filename:=savefolder & filename, Local:=True)
set ws1 = wb1.worksheets(1)
'code related to what I am wanting to do to the data to 'clean it up'
wb1.close true
filename = dir()
Loop
End Sub
If you're using the TextToColumns
function, you can use FieldInfo:=Array(1, 4)
parameter. 如果使用的是TextToColumns
函数,则可以使用FieldInfo:=Array(1, 4)
参数。
I was having a similar issue and this worked for me (besides using Local:=True
) 我有一个类似的问题,这对我有用(除了使用Local:=True
)
It only worked using both "solutions". 它只能使用两个“解决方案”。
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.