Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-02-2021, 04:44 PM
Guessed's Avatar
Guessed Guessed is offline Search for first occurrence of certain letter in beginning of a paragraph Windows 10 Search for first occurrence of certain letter in beginning of a paragraph Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This looks like it works.
Code:
Sub AddLetterHeads()
  Dim iPar As Integer, sLett As String, aRng As Range, sPrev As String
  Set aRng = ActiveDocument.Range
  For iPar = aRng.Paragraphs.Count To 1 Step -1
    sLett = aRng.Paragraphs(iPar).Range.Characters(1)
    If iPar > 1 Then sPrev = aRng.Paragraphs(iPar).Previous.Range.Characters(1)
    If sPrev <> sLett Or iPar = 1 Then
      aRng.Paragraphs(iPar).Range.InsertBefore sLett & vbCr
      aRng.Paragraphs(iPar).Style = "BibloChar"   'the new paragraph
    End If
  Next iPar
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Tags
vba code, vba find and replace, word vba code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for first occurrence of certain letter in beginning of a paragraph Replace a character only if it is at the beginning of the paragraph. donpopo Word 2 11-11-2018 11:32 PM
Search for first occurrence of certain letter in beginning of a paragraph Space tab at the beginning of each paragraph in a chapter village Word 3 07-20-2018 01:48 AM
Search for first occurrence of certain letter in beginning of a paragraph Wildcards - Sequence of Numbers at the Beginning of Each Paragraph qubie Word 1 11-30-2017 02:03 PM
Search for first occurrence of certain letter in beginning of a paragraph search for consecutive words beginning with capital letter cheech1981 Word 7 11-24-2017 12:50 PM
Search for first occurrence of certain letter in beginning of a paragraph How to keep a word with capitalized first letter, but not at the beginning of a sentence? xiangwulu Word 4 10-31-2014 09:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:27 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