Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2024, 03:48 PM
Guessed's Avatar
Guessed Guessed is offline Bold certain parts of bookmarks text code help Windows 10 Bold certain parts of bookmarks text code help 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

The initial post included this line


If Me.CheckBox1.Value

This made me think that you had the checkboxes on a VBA Userform since 'Me' is a reference to a VBA userform.

If you ACTUALLY have Content Control Checkboxes in the body of the document then the coding can be simpler. Put this code into the ThisDocument module. You won't need any other code if you have set up your Tag/Title combinations with the Content Controls.
Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean)
  Dim aCC2 As ContentControl, sTag As String
  If aCC.Type = wdContentControlCheckBox Then
    sTag = aCC.Tag
    Set aCC2 = ActiveDocument.SelectContentControlsByTitle(sTag)(1)
    With aCC2
      If aCC.Checked Then
        aCC2.Range.Text = "Title" & vbTab & "First line"
        aCC2.Range.Words(1).Bold = True
      Else
        aCC2.SetPlaceholderText Text:="Blank"
        aCC2.Range.Text = ""
      End If
    End With
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 01-15-2024, 03:00 AM
WordVB WordVB is offline Bold certain parts of bookmarks text code help Windows 11 Bold certain parts of bookmarks text code help Office 2016
Novice
Bold certain parts of bookmarks text code help
 
Join Date: Jan 2024
Location: Ireland
Posts: 12
WordVB is on a distinguished road
Default

Thanks very much everyone.

I don't think I got to the level where I can use tags at this stage, but the last code works very well with Tag Title combinations. Can you help me with the last bit of the code please, what do I need to change in the code if I want to add additional checkboxes and text? Additional checkbox would have additional corresponding text. Appreciate your help, this project is almost finished.
Reply With Quote
  #3  
Old 01-15-2024, 04:44 AM
WordVB WordVB is offline Bold certain parts of bookmarks text code help Windows 11 Bold certain parts of bookmarks text code help Office 2016
Novice
Bold certain parts of bookmarks text code help
 
Join Date: Jan 2024
Location: Ireland
Posts: 12
WordVB is on a distinguished road
Default

Think I have it sorted. Works so far. Thanks for all your help everyone.

Private Sub Document_ContentControlOnexit(ByVal aCC As ContentControl, Cancel As Boolean)
Dim aCC2 As ContentControl, sTag As String
Select Case aCC.Title
Case "C1"
If aCC.Type = wdContentControlCheckBox Then
sTag = aCC.Tag
Set aCC2 = ActiveDocument.SelectContentControlsByTitle(sTag)( 1)
With aCC2
If aCC.Checked Then
aCC2.Range.Text = "Title" & Chr(10) & "First line"
aCC2.Range.Words(1).Bold = True
Else
aCC2.SetPlaceholderText Text:="Blank"
aCC2.Range.Text = ""
End If
End With
End If
End Select
Select Case aCC.Title
Case "C2"
If aCC.Type = wdContentControlCheckBox Then
sTag = aCC.Tag
Set aCC2 = ActiveDocument.SelectContentControlsByTitle(sTag)( 1)
With aCC2
If aCC.Checked Then
aCC2.Range.Text = "Title1" & Chr(10) & "First line1"
aCC2.Range.Words(1).Bold = True
Else
aCC2.SetPlaceholderText Text:="Blank"
aCC2.Range.Text = ""
End If
End With
End If
End Select
End Sub
Reply With Quote
  #4  
Old 01-16-2024, 09:35 AM
WordVB WordVB is offline Bold certain parts of bookmarks text code help Windows 11 Bold certain parts of bookmarks text code help Office 2016
Novice
Bold certain parts of bookmarks text code help
 
Join Date: Jan 2024
Location: Ireland
Posts: 12
WordVB is on a distinguished road
Default

The project is almost complete now, thank you for all your suggestions, using content control definitely streamlined the process.

I have spent much time on research but hit a brick wall again. I am sure there were much efficient ways around it but the word document works well and checkboxes populate text in rich text areas so I would be reluctant to make any significant changes to the code, however the text needs formatting.

Unfortunately, one paragraph is over two pages long and should have different levels of lists formatting (Bullet points (chr(149), sub a) level and sub-sub i) level. Is there a way to select a range within the text and apply the list format? I am able to apply one list format to a whole range but not for parts of range and different levels of lists (as per above). Any help would be greatly appreciated again.



Code:
Private Sub Document_ContentControlOnexit(ByVal aCC As ContentControl, Cancel As Boolean)
   Dim aCC2 As ContentControl, sTag As String
   Select Case aCC.Title
     Case "Title1"
 If aCC.Type = wdContentControlCheckBox Then
    sTag = aCC.Tag
    Set aCC2 = ActiveDocument.SelectContentControlsByTitle("Title")(1)
    With aCC2
      If aCC.Checked Then
        aCC2.Range.Text = "HEADING BOLD" & Chr(10) & Chr(10) & "Text text text text text." & Chr(10) & Chr(10) & "Text text text text text" _
        & Chr(10) & Chr(10) & "Bullet point text" _
        & Chr(10) & Chr(10) & "a) List text" & Chr(10) & "b) List text" _
        & Chr(10) & Chr(10) & "i) List text" & Chr(10) & "ii) List text"
        aCC2.Range.Words(1).Bold = True
        aCC2.Range.Words(2).Bold = True
        aCC2.Range.Font.Name = "Calibri"
        aCC2.Range.Font.Size = 11
        aCC2.Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
        aCC2.Range.ParagraphFormat.SpaceAfter = 0
      Else
        aCC2.SetPlaceholderText Text:="Blank"
        aCC2.Range.Text = ""
      End If
    End With
  End If
End Select
Reply With Quote
Reply

Tags
bold header



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bold certain parts of bookmarks text code help How to code a Find&Replace macro to remove a tab and bold the entire para Frogoogue Word VBA 4 05-30-2022 09:15 AM
Bold certain parts of bookmarks text code help bold (or unbold) section of text instead of bold toggling Burt Word 6 04-06-2019 09:09 AM
Bold certain parts of bookmarks text code help Text in #1 is made bold, rest of the document is edited, text in #1 is now not bold footer-assistance Word 1 06-29-2015 03:49 AM
Bold certain parts of bookmarks text code help Not Bold text but it comes up bold Pluviophile Word 7 10-22-2013 10:29 AM
Bold certain parts of bookmarks text code help VBA code to extract specific bookmarks from multiple word files Rattykins Word VBA 4 06-27-2012 10:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:43 PM.


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