文檔中重複出現「香蕉」、「公司 Logo」、「產品圖」等文字,需統一替換為對應圖片。手動複製貼上極慢,「尋找取代」支援 ^c(剪貼板內容)代碼,一鍵批量完成。
^c。




^c 代表執行取代當下的剪貼板內容,中途複製其他內容會失效 → 操作前確保目標圖片在剪貼板最新。Sub BatchReplaceTextWithImage()
Dim dict As Object: Set dict = CreateObject("Scripting.Dictionary")
dict("香蕉") = "C:\Images\banana.png"
dict("蘋果") = "C:\Images\apple.png"
dict("公司") = "C:\Images\logo.png"
For Each key In dict.Keys
With ActiveDocument.Content.Find
.Text = key
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
' 此處需配合 InlineShapes.AddPicture 實際插入,略
Next
End Sub