[英]VBA Export and save to CSV issues
Found the below code online, though it's a bit strange when I run the macro for dates as my dates will convert from: [DD/MM/YYYY] to [MM/DD/YYYY] 在网上找到了以下代码,但是当我为日期运行宏时有点奇怪,因为我的日期将从:[DD / MM / YYYY]转换为[MM / DD / YYYY]
example: 31/07/2017 to 07/31/2017. 例如:2017年7月31日至2017年7月31日。
anyone able to assist, I would want to keep it was [DD/MM/YYYY]. 任何能够协助的人,我都希望保留为[DD / MM / YYYY]。
Refer to below: 请参阅以下内容:
Dim strName As String
Dim filepath As String
Application.ScreenUpdating = False
strName = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name & " " & ActiveSheet.Name & ".csv"
ActiveSheet.Copy 'copy the sheet as a new workbook
ActiveWorkbook.SaveAs Filename:=strName, FileFormat:=xlCSV
ActiveWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
MsgBox "File has been Created and Saved as: " & vbCr & strName, , "Copy & Save Report"
thanks, 谢谢,
Depending on your local language settings (specified in Control Panel), the following should work: 根据您的本地语言设置(在“控制面板”中指定),以下方法应该起作用:
ActiveWorkbook.SaveAs Filename:=strName, FileFormat:=xlCSV, Local:=True
This should ideally be used by specifying the TextCodepage
parameter of the SaveAs
method. 理想情况下,应通过指定
SaveAs
方法的TextCodepage
参数来使用它。 However, according to MSDN reference , this parameter is ignored for all languages of Excel. 但是,根据MSDN参考 ,对于所有Excel语言都将忽略此参数。
A previous question on SO addresses this, and suggests instead using FileFormat:=xlUnicodeText
, and then setting the extension to .csv
, ie: 关于SO的先前问题解决了此问题,并建议使用
FileFormat:=xlUnicodeText
,然后将扩展名设置为.csv
,即:
ActiveWorkbook.SaveAs Filename:=strName & ".csv", FileFormat:=xlUnicodeText
However, this does not seem to work for my part when testing your scenario. 但是,这在测试您的方案时似乎不适用于我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.