我沒有Word或Excel宏的經驗,但我想將Excel數據導入幾個文件,每個文件包含相同的內容。 (我認爲這個任務畢竟不是那麼複雜,我試圖通過formletter函數完成它,但是當我失敗時,我意識到它確實比我想象的複雜得多。然後我想,也許這是正確的地方要求adivce ...)。通過搜索和替換Excel數據到Word模板 - 多個文檔
示例數據(Excel數據):
Varname Value
Var1 2
Var2 3
Var3 0.5
...
的示例數據(Word模板)
The following treats the topic on "Varname". Its Value is "Value".
那麼到底應該是這樣的:
The following treats the topic Var1. Its Value is 2. (saved as Var1.doc or even better Var1.txt, but *.doc would be ok for the beginning!)
The following treats the topic Var2. Its value is 3. (saved as Var2.doc)
The following treats the topic Var3. Its value is 0.5. (saved as Var3.doc)
...
雖然實際文本要複雜得多,不應該是代碼本身的一部分。所以我認爲最好的解決方案必須是「查找」和「替換」。由於我對Word/Excel中的宏完全陌生,因此無法找到如何爲「替換」功能實現Excel數據。
' Replace-Excel-Data-Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = """Varname"""
.Replacement.Text = "**???**"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = """Value"""
.Replacement.Text = "**???**"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
我很抱歉,如果這個問題已經被問過,我無法找到適當的幫助到現在爲止,可能是由於我的非常有限的這種宏觀的東西..知識爲您的意見,許多在此先感謝! :)
我的答案是晚了一點,但還是謝謝你!最後我是這樣做的:) – GreenDot72