由于我是VBA的新手,所以我创建了一个代码,该代码使用户可以打开.CSV(系统生成的)文件并删除列,然后将其关闭以进行重命名。
当我运行宏时,它不会影响.CSV工作簿,并且会像以前一样保留所有日期格式"25/02/2019"
。但是运行宏后,当我使用文本文件打开它时,在文本文件中显示为“ 25/02/19”的日期。如何解决此问题?
Option Explicit
Sub Rename_workbook()
Dim fileName As String
Dim filePath As String
filePath = ("D:\VBA\")
fileName = Dir(filePath & "System_567875_20190228*" & ".csv")
Workbooks.Open (filePath & fileName), local:=True
Columns("Q:Q").select
selection.delete 'Deleting column'
columns("A:Z").Autofit
Activeworkbook.Close savechanges:=True 'Command to close the "Quality Report*"'
if fileName <> "" Then
Set fso = CreateObject("Scripting.FileSystemObject") 'renaming closed file'
fso.Movefile filePath & fileName, filePath & "Quality Report.csv")
End If
End Sub