Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2018, 12:48 AM
dagerr dagerr is offline bold paragraph, add sign after first word.... Windows 7 64bit bold paragraph, add sign after first word.... Office 2007
Novice
bold paragraph, add sign after first word....
 
Join Date: Jan 2018
Posts: 5
dagerr is on a distinguished road
Default bold paragraph, add sign after first word....

Hi Everyone,
Could You help me with that problem.


In text I want first paragraph to be bold then, after first word add a sign and at the end, before text: so or jas or mf give a tab. Also so, mf and jas should be bold. Example below:
Original text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. [enter]
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. so

After:
Lorem► ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. [enter]
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. [tab]so

Could Anyone help?
Thanks in Advanced.
Reply With Quote
  #2  
Old 01-12-2018, 01:56 AM
gmayor's Avatar
gmayor gmayor is offline bold paragraph, add sign after first word.... Windows 10 bold paragraph, add sign after first word.... Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

That should be fairly simple e.g. with the cursor in the first of the two paragraphs run the following
Code:
Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 12 Jan 2018
Dim oRng As Range
Dim strEndWord() As Variant
Dim i As Long
    strEndWord = Array("so", "jas", "mf")
    Set oRng = Selection.Paragraphs(1).Range
    If oRng.Start = ActiveDocument.Paragraphs.Last.Range.Start Then
        MsgBox "You cannot process the last paragraph!"
        GoTo lbl_Exit
    End If
    With oRng
        .Font.Bold = True
        .End = .Words(1).End - 1
        .InsertAfter ChrW(9658)
        .End = .End + 1
        .Font.ColorIndex = wdRed
        .End = .Paragraphs(1).Range.End
        .End = .Next.Paragraphs(1).Range.End - 1
        .Start = .Words.Last.Start
        For i = 0 To UBound(strEndWord)
            If strEndWord(i) = LCase(.Text) Then
                .InsertBefore vbTab
                .Font.Bold = True
                Exit For
            End If
        Next i
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
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 01-12-2018, 02:29 AM
dagerr dagerr is offline bold paragraph, add sign after first word.... Windows 7 64bit bold paragraph, add sign after first word.... Office 2007
Novice
bold paragraph, add sign after first word....
 
Join Date: Jan 2018
Posts: 5
dagerr is on a distinguished road
Default

Gmayor, You Are my Hero!
But Could You modify this macro because bolding of so, mf and jas working only with text with two paragraphs and I want to work it with n paragraphs (so, mf and jas will be always at the end of text).
Thanks
Reply With Quote
  #4  
Old 01-12-2018, 05:48 AM
gmayor's Avatar
gmayor gmayor is offline bold paragraph, add sign after first word.... Windows 10 bold paragraph, add sign after first word.... Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

That's what your example showed. If you want to check the last word in the document against the list, then set the range end there instead. e.g.

Code:
Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 12 Jan 2018
Dim oRng As Range
Dim strEndWord() As Variant
Dim i As Long
    strEndWord = Array("so", "jas", "mf")
    Set oRng = Selection.Paragraphs(1).Range
    With oRng
        .Font.Bold = True
        .End = .Words(1).End - 1
        .InsertAfter ChrW(9658)
        .End = .End + 1
        .Font.ColorIndex = wdRed
        .End = ActiveDocument.Range.End - 1
        .Start = .Words.Last.Start
        For i = 0 To UBound(strEndWord)
            If strEndWord(i) = LCase(.Text) Then
                .InsertBefore vbTab
                .Font.Bold = True
                Exit For
            End If
        Next i
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
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
  #5  
Old 01-12-2018, 07:31 AM
dagerr dagerr is offline bold paragraph, add sign after first word.... Windows 7 64bit bold paragraph, add sign after first word.... Office 2007
Novice
bold paragraph, add sign after first word....
 
Join Date: Jan 2018
Posts: 5
dagerr is on a distinguished road
Default

I don't understand properly. Where I should set the range end?
Reply With Quote
  #6  
Old 01-12-2018, 10:33 PM
gmayor's Avatar
gmayor gmayor is offline bold paragraph, add sign after first word.... Windows 10 bold paragraph, add sign after first word.... Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

You set the end of the range to immediately after the letters you want to bold. The second example has the range set at the end of the document. Initially you suggested that was the end of the paragraph after the paragraph to be made bold. Then you said it was the end of the document. I have catered for both.
__________________
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
  #7  
Old 01-15-2018, 05:19 AM
dagerr dagerr is offline bold paragraph, add sign after first word.... Windows 7 64bit bold paragraph, add sign after first word.... Office 2007
Novice
bold paragraph, add sign after first word....
 
Join Date: Jan 2018
Posts: 5
dagerr is on a distinguished road
Default

Yes, it is my fault i did not try a second code.
If this is not a problem I will add some precise correction to improve a macro.
1. Adding a sign (ChrW(9658)) after first word could be repleaced to adding sing to group of words array ("ROPCZYCE", "IWIERZYCE" ,e.t.c...) important thing is that it should be only taking words in uppercase If there will be no one of word from array do not add a sign.
2. first and second paragraph should be bold. Not in every document two paragraphs should bold. Notice that in example file two paragraphs are title and paragraph below title. I don't know how to see a reguality of this case so maybe left it as two paragraphs bold in every time.
3. so, mf and jas should bold either and before this words add tab but "so" or "mf" or "jas" will be not in every document.
4. At the end of last part of document it could be array ("FOTO: M.FRON", "FOTO: S.OSKARBSKI", e.t.c..) - change a size of it to 5, and timesnewroman font.
5. After a text from array ("FOTO: M.FRON", "FOTO: S.OSKARBSKI", e.t.c..). to the end of document text should be timesnewroman font and .LineSpacing = LinesToPoints(0.9).
Note that not in every document will be points 4 and 5
I hope that is clear.
I've attached word file with example wich clarify what i mean.
Attached Files
File Type: docx macro examples.docx (16.9 KB, 12 views)
Reply With Quote
  #8  
Old 01-21-2018, 11:47 PM
dagerr dagerr is offline bold paragraph, add sign after first word.... Windows 7 64bit bold paragraph, add sign after first word.... Office 2007
Novice
bold paragraph, add sign after first word....
 
Join Date: Jan 2018
Posts: 5
dagerr is on a distinguished road
Default

Anyone helps? Please.
Reply With Quote
  #9  
Old 07-15-2023, 12:29 PM
geekforlife geekforlife is offline bold paragraph, add sign after first word.... Windows 11 bold paragraph, add sign after first word.... Office 2021
Novice
 
Join Date: Jul 2023
Posts: 1
geekforlife is on a distinguished road
Default

I've shared a macro that will automatically update paragraph labels for one or all paragraphs with the same style. And what's better than built in "Autoformat as you type" option is my macro uses Character Style so you can also modify all paragraph label formatting easily. Here's my blog post explaining: Powerful Paragraph Labeling in Microsoft Word – Samir Adams Ghosh's blog
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting part of a paragraph bold Fred256 Word VBA 4 10-07-2016 02:54 PM
How to parse bold sections of a paragraph? XmisterIS Word VBA 2 03-31-2014 02:54 PM
bold paragraph, add sign after first word.... Set paragraph text to bold. Sorcerer13 Word 1 09-04-2012 11:08 AM
bold paragraph, add sign after first word.... Word doesn't jumps tothe next lane when finds the dash sign!!!! why? Jamal NUMAN Word 3 04-10-2011 02:49 PM
paragraph sign appearing in document ajetrumpet Word 1 08-24-2010 05:46 AM

Other Forums: Access Forums

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