我应该如何更改下面的脚本,因为它可以替换Word文档标题中的日期?它适用于Word文档的正文,但不适用于标题?我应该改变什么?
Sub Main
Dim iDate, sSearchValue, sReplaceValue
iPath = C:/TEMP/test.docx
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWSH = CreateObject( "WScript.Shell" )
Set objWRD = GetObject("","Word.Application")
iDate = Date
objWRD.Visible = FALSE
sSearchValue = "<DATE>"
sReplaceValue = iDate
If sReplaceValue <> "" Then
strReplace objWRD, sSearchValue, sReplaceValue, 2
End If
wrdTemplate.SaveAs objFSO.BuildPath(iPath, "test.docx")
wrdTemplate.Close
objWRD.Quit
iPath = objFSO.BuildPath(iPath, "test.doc")
End Sub
Main
Function strReplace(obj, sSearchValue, sReplaceValue, nType )
obj.Selection.Find.ClearFormatting
obj.Selection.Find.Replacement.ClearFormatting
obj.Selection.Find.Text = sSearchValue ' Search string
obj.Selection.Find.MatchCase = False
obj.Selection.Find.MatchWholeWord = False
obj.Selection.Find.MatchWildcards = False
obj.Selection.Find.MatchSoundsLike = False ' True ????
obj.Selection.Find.MatchAllWordForms = False
obj.Selection.Find.Forward = True
obj.Selection.Find.Wrap = 1 ' = wdFindContinue
obj.Selection.Find.Format = False
obj.Selection.Find.Replacement.Text = sReplaceValue ' Replace string
obj.Selection.Find.Execute ,,,,,,,,,,nType ' Type=2 wdReplaceAll
End Function ' >>>>> strReplace <<<<<
这就是全部。