Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-20-2017, 06:27 AM
ArieH ArieH is offline word macro To insert text at the beginning and at end of paragraph Windows 10 word macro To insert text at the beginning and at end of paragraph Office 2007
Novice
word macro To insert text at the beginning and at end of paragraph
 
Join Date: Aug 2017
Posts: 10
ArieH is on a distinguished road
Default word macro To insert text at the beginning and at end of paragraph

Hello,
I need to add a sighn like "/>" at the beginning of each paragraph which normally is in style Normal, and after the last character at the end of the paragraph "/>"
I tried this VB, but it cause some problem on the headings , so I need to use different methods and to put the BeforeText and AfterText within the paragraph and not at the headings. Do someone have any suggestion or example?


Dim doc As Document
Dim para As Paragraph

Const BeforeText = "</"
Const AfterText = "/>"
Application.ScreenUpdating = False
Set doc = ActiveDocument

For Each para In doc.Paragraphs
If para.Style = doc.Styles(wdStyleHeading1) Then


para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
If para.Style = doc.Styles(wdStyleHeading2) Then
para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
If para.Style = doc.Styles(wdStyleHeading3) Then
para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
If para.Style = doc.Styles(wdStyleHeading4) Then
para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
If para.Style = doc.Styles(wdStyleHeading5) Then
para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
Next para



End Sub
Reply With Quote
 

Tags
macro, macro help, table control, word 2007

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
word macro To insert text at the beginning and at end of paragraph Can't insert space at the beginning of a line in Word p89.schneider Word 6 03-24-2016 11:38 PM
word macro To insert text at the beginning and at end of paragraph Macro to Insert text into the beginning on specific paragraphs unless the paragraph is blank caboy Word VBA 2 04-01-2015 07:00 AM
word macro To insert text at the beginning and at end of paragraph VBA code for Microsoft Word macro — select text and insert footnote ndnd Word VBA 10 01-06-2015 01:47 PM
word macro To insert text at the beginning and at end of paragraph Macro to insert multiple pictures to word to a specific size and text wrap mescaL Word VBA 3 11-03-2014 10:51 PM
Looping macros to add text to beginning and end of a paragraph pachmarhi Word VBA 0 02-16-2009 06:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:00 AM.


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