crazydragon84
Board Regular
- Joined
- Feb 19, 2015
- Messages
- 195
Hi I have bunch of similar word doc that has variable amount of sentences/paragraphs that needs to be inserted. I have a table in excel that lists out each paragraph that needs to go into each document. I have 40 documents and each documents will have different number of paragraph. In each document, i have a text that you can search for in the section that paragraphs needs to be inserted (e.g. "Paste_text_HERE"). I am executing the macro from excel which basically loops through a list of document names, filter the table for paragraphs that needs to be pasted into the document (which is range of cells, not specific cell), copies that range, find the "Paste_Text_here" on the document and paste it in there. I am having a difficult time executing the last step, which is pasting into the doc. After i paste it, i also want to format the paragraphs that were inserted to use certain font style. Here is the code I am using the identify the place that paragraphs needs to be inserted, and my attempt to paste the data there.
Any help is appreciated. Thank you.
Code:
Set docWD = appWd.Documents.Open(File_Path & rng.Value & ".docx")
Set wdFind = appWd.Selection.Find
With wdFind
.MatchCase = True
.Text = "Paste_Text_here"
.Execute
End With
With selection.Range
.Paste '<---- this is where the error occurs
.Font.Name = "XYZ"
.Font.Color = Black
.Font.Bold = False
.Font.Italic = False
.Font.Allcaps = False
.Font.Size = 8
End With
Any help is appreciated. Thank you.