I would like to do the following:
In Excel, create tables and define the range (e.g. A1 to B13 is "Arf", saved in the file
With VBA, move from Excel to an open Word document
Within the open Word document, search for a string (e.g. "[Table goes here]")
Replace Word string with Excel defined range (e.g. [Table goes here] is replaced by "Arf")
I would have many defined ranges for many different tables and depending on which pre-defined table I am working with in Excel, I would macro to have that defined range imported to the respective string in Word
So far I have found lots of code for going in and changing text in a file location, but I would like this to be for whatever Word file is currently open (working in both files, Excel & Word, concurrently).
I don't really have existing code for this, since I don't know how to do it, but let me try to give what I'm thinking:
Sub Replace_Word_String_with_Excel_Range()
Application.Goto Reference:="Arf"
Selection.Copy
Application(Word).Find.Replacement
With Selection.Find
.Text = "[Table goes here]"
.Replacement.value = "Arf"
End With
End Sub
I feel like I can create an Excel file and create templates, defining the tables. I would have them all named (e.g. Arf, Bark, & Woof). What I don't understand is how to "alt-tab" to Word via code. Additional confusion on my part is how to paste the whole Excel defined section via the Replacement.Value function.
Any help to figure this out would be much appreciated. As I am actively working on this, I will try to edit this post and update accordingly.
Thanks!