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.
 
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....
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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!
 
Upvote 0
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]
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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
Back
Top