![vba word build range by paragraph vba word build range by paragraph](https://software-solutions-online.com/wp-content/uploads/2014/05/word-vba-split-document1.png)
#VBA WORD BUILD RANGE BY PARAGRAPH CODE#
Second block of code (identify source lines and copy to article header lines, based on formatting). Set oRng = ActiveDocument.Range(Start:=oRngstart.End, End:=)
![vba word build range by paragraph vba word build range by paragraph](https://www.automateexcel.com/excel/images/AutoMacro/vba-for-each-ws-in-worksheets.png)
![vba word build range by paragraph vba word build range by paragraph](https://vbaoverall.com/wp-content/uploads/2020/06/image-32-1024x543-min.png)
Set oRng = ActiveDocument.Range(Start:=oRngstart.End, End:=oRngend.Start) MsgBox excludedTerms(i) & " detected - skipping" If InStr(1, Selection.Text, excludedTerms(i), vbTextCompare) Then Style = ActiveDocument.Styles(wdStyleHeading1) My intention was to loop the code to identify the ranges and as it identifies each range, run the code to copy the source lines to the headers within that range, but I can't find a way to limit the Selection.Find search to a specific Range (oRng).Ĭan anyone help me out with this, please?įirst block of code (Identify ranges between applicable section headers) Sub SourceToArticleHeadersP2() What I need to do is run the first set of code (which is based around Selection.Find) within the ranges specified by the second set of code. I also have working code to identify the sections of the text where the first set of code needs to be applied, by creating ranges (oRng) between applicable section headers, looping through the document section by section. Situation: I have working code to find the article source lines and copy them to the end of the article headers (looping through the whole document using Selection.Find). However, certain sections need to be excluded from this operation, if the section header is a specific term. I need to select the source line in the article (single paragraph in bold) and copy it to the end of the article header (single paragraph in Header2 style). I need to limit the Selection.Find search to the range defined by oRng.īackground: I have a variable list of news articles divided into sections under headers (single paragraph in Header1 style), which are also variable. One identifies a range of text (oRng), while the other runs a Selection.Find search to alter some text. I have two blocks of Word VBA code here that each work fine separately, but which I need to combine in order to obtain the desired result.