excel操作word,替换文本
生活随笔
收集整理的這篇文章主要介紹了
excel操作word,替换文本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.在Excel vba編輯器-工具-引用中添加對word.14的引用。
2.利用word vba查找替換功能替換word文本中文字。
'打開模板文件 Set objApp = CreateObject("Word.Application") objApp.Visible = TrueSet objDoc = objApp.Documents.Open(strTemplates, , False)'開始替換模板預置變量文本 With objApp.Application.Selection .Find.ClearFormatting .Find.Replacement.ClearFormattingWith .Find .Text = "{$合同編號}" .Replacement.Text = contact_NO End With .Find.Execute Replace:=wdReplaceAllWith .Find .Text = "{$甲方}" .Replacement.Text = side_A End With .Find.Execute Replace:=wdReplaceAllWith .Find .Text = "{$乙方}" .Replacement.Text = side_B End With .Find.Execute Replace:=wdReplaceAllEnd With '將寫入數據的模板另存為文檔文件objDoc.SaveAs strFileName objDoc.Saved = True'MsgBox "合同文本生成完畢!", vbYes + vbExclamation objDoc.Close objApp.Quit?
3.vba對象幫助網站。vba幫助網站
總結
以上是生活随笔為你收集整理的excel操作word,替换文本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unity中Time.deltaTime
- 下一篇: Unity中Quaternion的含义及