Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-23-2017, 09:26 PM
gattaca714 gattaca714 is offline Find word, Insert Paragraph and bookmark Windows 7 64bit Find word, Insert Paragraph and bookmark Office 2010 32bit
Novice
Find word, Insert Paragraph and bookmark
 
Join Date: Mar 2017
Posts: 2
gattaca714 is on a distinguished road
Default Find word, Insert Paragraph and bookmark

Hello I found this macro and Im trying to modify it to fit my application.

If the word Roll Call exist, select it and insert a paragraph after it, insert a bookmark. Any leads would be appreciate it.

Sub macro2()
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="Roll Call", Forward:=False
If myRange.Find.Found = True Then Selection.TypeParagraph
ActiveDocument.Bookmarks.Add Name:="mark"
End Sub
Reply With Quote
  #2  
Old 03-23-2017, 10:06 PM
gmayor's Avatar
gmayor gmayor is offline Find word, Insert Paragraph and bookmark Windows 10 Find word, Insert Paragraph and bookmark Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following should do the job
Code:
Sub macro2()
Dim myRange As Range
    Set myRange = ActiveDocument.Content
    With myRange.Find
        Do While .Execute(FindText:="Roll Call", MatchCase:=True) 'Find the text
            myRange.InsertParagraphAfter 'insert a paragraph break after it
            myRange.End = myRange.End + 1 'move the end of the range beyond the paragraph break
            myRange.Collapse 0 'Collapse the range to its end
            ActiveDocument.Bookmarks.Add Name:="mark", Range:=myRange 'add a bookmark at the range
            myRange.Select 'optionally select it
            Exit Do 'Stop looking for the text
        Loop
    End With
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 03-24-2017, 09:23 PM
gattaca714 gattaca714 is offline Find word, Insert Paragraph and bookmark Windows 7 64bit Find word, Insert Paragraph and bookmark Office 2010 32bit
Novice
Find word, Insert Paragraph and bookmark
 
Join Date: Mar 2017
Posts: 2
gattaca714 is on a distinguished road
Default

Thank you, this appears to work as expected
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Bookmark, move to bookmark, execute code, repeat raymm3852 Word VBA 10 04-15-2016 06:21 PM
Find word, Insert Paragraph and bookmark Is there anyway I can insert an easy bookmark in word? BayhDole Word 2 07-21-2015 08:43 PM
Find last word in paragraph and delete it Dave T Word VBA 3 05-21-2015 12:40 AM
Find word, Insert Paragraph and bookmark Delete bookmark and paragraph which is blank dsjk9190 Word VBA 2 01-22-2015 01:15 AM
Find word, Insert Paragraph and bookmark [Word 2007] How to hyperlink directly another word file chapter/paragraph/bookmark? LeeFX Word 4 05-05-2011 05:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:31 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft