如何遍历文件夹中的每个文档并更新修改日期

时间:2015-07-21 14:38:24

标签: vbscript automation

这是我到目前为止 - 它打开excel和word,但不更新时间。只是保存文件足以更新时间?

strComputer="."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'ENTER FILE PATH TO ROOT DIRECTORY HERE Win32_Directory.Name='C:\___________'
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\'} Where ResultClass = CIM_DataFile")


Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = TRUE
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
For Each objFile In colFileList
If objFile.Extension = "xls" Or objFile.Extension = "xlsx" Then
    Set objWorkbook = objExcel.Workbooks.Open(objFile.Name)
    objWorkbook.Save()
    objExcel.Quit
ElseIf objFile.Extension = "doc" or objFile.Extension = "docx" Then
    Set objDoc = objWord.Documents.Open(objFile.Name)
    objDoc.Save(objFile.Name)
    objWord.Quit
End If
Next

0 个答案:

没有答案