copy range from excel into certain section of word doc

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.

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.
 

crazydragon84

Board Regular
Joined
Feb 19, 2015
Messages
195
i'm still having issue finding a text string with number at the end. i don't understand why i can't Find, but i can find and replace the same text....
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

crazydragon84

Board Regular
Joined
Feb 19, 2015
Messages
195
ok. i think i figured it out. The issue was only when I was pasting the New Deals, then Exited deals. For whatever reason, the "Find" would not work right after it pasted something. so i had to add ActiveDocument.Range(1).Select after the paste then the next Find worked fine even with the number in it at the end. Thanks so much for your help shknbk2!
 

shknbk2

Board Regular
Joined
Mar 5, 2016
Messages
248
You're welcome.

Also, in your replace code block, you included the Forward and Wrap parameters. How about trying them in the Find (not replace) block as well?
Code:
[COLOR=#333333].Execute Forward:=True, Wrap:=wdFindContinue[/COLOR]
 

Watch MrExcel Video

Forum statistics

Threads
1,126,893
Messages
5,621,480
Members
415,844
Latest member
Reda Fouad Ramzy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top