本帖最后由 flashercs 于 2022-2-10 16:05 编辑
wsf脚本.
链接:https://pan.baidu.com/s/13h6DQEaduumObMqLX6cECA
提取码:ehn2- <?xml version="1.0" encoding="utf-8" ?>
- <package xmlns="http://schemas.microsoft.com/WindowsScriptHost">
- <job>
- <script language="VBScript">
- <![CDATA[
- On Error Resume Next
- Const conFind = "1月1日" '要替换的日期
- Const wdReplaceAll = 2
- Const conExtension = "|docx|doc|"
-
- Dim dtm,strDtm,wordApp,fso
- dtm = Now
- strDtm = Month(dtm) & "月" & Day(dtm) & "日"
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set wordApp = CreateObject("Word.Application")
- wordApp.DisplayAlerts = False
- GenFolder fso.GetFolder(fso.GetParentFolderName(WScript.ScriptFullName))
- wordApp.Quit
- MsgBox "Done"
- Set wordApp = Nothing
- Set fso = Nothing
-
- Sub GenFolder(oFolder)
- On Error Resume Next
- Dim oFile,oSubFolder
- For Each oFile In oFolder.Files
- If InStr(1,conExtension,fso.GetExtensionName(oFile.Name),vbTextCompare) > 0 Then
- GenFile oFile
- End If
- Next
- For Each oSubFolder In oFolder.SubFolders
- GenFolder oSubFolder
- Next
- End Sub
- Sub GenFile(oFile)
- On Error Resume Next
- Dim doc
- Set doc = wordApp.Documents.Open(oFile.Path)
- ReplaceWords doc
- doc.Save
- End Sub
- Sub ReplaceWords(document)
- On Error Resume Next
- With document.Content.Find
- .ClearFormatting
- .Text = conFind
- With .Replacement
- .ClearFormatting
- .Text = strDtm
- End With
- .Execute , , , , , , , , , , wdReplaceAll
- End With
- End Sub
- ]]>
- </script>
- </job>
- </package>
复制代码
|