Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 01-16-2024, 12:48 PM
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 Italophile,



It seems I am drifting away from what was originally intended. It is fully understandable as there are no universal code or a code which would suit all. Different suggestions follow different interpretations and again it is because I haven't painted the full picture.

I am working on a document (.docx) which has predetermined standard paragraphs which do not change. 14 pages in total. I need to insert additional paragraphs (with bold titles, bullet points and levels of number formats) in the middle of the document in certain places based on checkboxes at the front page of the document.

So far I have managed to create 10 checkboxes, linked and populated text in rich format content controls in those certain areas in the middle of the document. The issue is formatting of the text (bold titles, bullet points and levels of number formats).

I like the idea to use building blocks, and have already saved the texts required in Quick Parts.

Can I slightly change my current code (which works with checkboxes and rich text controls) to insert saved text from Quick Parts into Building Block Galley Control?
Reply With Quote
  #17  
Old 01-16-2024, 01:39 PM
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

I think I managed to get it, however I can spot a potential issue. This macro enabled document will be uploaded and integrated into document storage and processing software (CCH accounts production and file management) for other users to use. The code has a reference to my local machine C drive... I will test it out tomorrow and see what pans out, but all looks great now.

Code:
Select Case aCC.Title
   Case "Title"
 If aCC.Type = wdContentControlCheckBox Then
    sTag = aCC.Tag
    Set aCC2 = ActiveDocument.SelectContentControlsByTitle("Title1")(1)
    With aCC2
      If aCC.Checked Then
      Application.Templates( _
        "C:\Users\XXXXXXXX\AppData\Roaming\Microsoft\Templates\Normal.dotm"). _
        BuildingBlockEntries("FINANCE").Insert Where:=aCC2.Range, RichText:=True
      Else
        aCC2.SetPlaceholderText Text:="Blank"
        aCC2.Range.Text = ""
      End If
    End With
  End If
End Select
Reply With Quote
  #18  
Old 01-16-2024, 03:01 PM
Italophile Italophile is online now Bold certain parts of bookmarks text code help Windows 11 Bold certain parts of bookmarks text code help Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Building-blocks can only be stored in a dotx so they are typically stored in the template used to create the document. That template remains attached to the document provided it is accessible, either on user machine or network folder. Accessing the AttachedTemplate in code can then be achieved without knowing its path.
Reply With Quote
  #19  
Old 01-16-2024, 03:10 PM
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

Quote:
Originally Posted by Italophile View Post
Building-blocks can only be stored in a dotx so they are typically stored in the template used to create the document. That template remains attached to the document provided it is accessible, either on user machine or network folder. Accessing the AttachedTemplate in code can then be achieved without knowing its path.
Thank you, so if I move both files, the doc and dotx to a new location, do I need to respecify the path in the code?
Reply With Quote
  #20  
Old 01-16-2024, 06:44 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: 3,977
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

I also support Italophile's advice, you should be storing the insertable formatted content into building blocks which can be retrieved anytime the macro requires it. Demo code to put it into a Rich Text Content Control looks like this.
Code:
Private Sub Document_ContentControlOnexit(ByVal aCC As ContentControl, Cancel As Boolean)
  Dim aCC2 As ContentControl, sTag As String, aTemplate As Template
  
  If aCC.Type = wdContentControlCheckBox Then
    sTag = aCC.Tag
    Set aTemplate = ActiveDocument.AttachedTemplate
    Set aCC2 = ActiveDocument.SelectContentControlsByTitle(sTag)(1)
    With aCC2
      If aCC.Checked Then
        aTemplate.BuildingBlockEntries("aa").Insert where:=aCC2.Range, RichText:=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
  #21  
Old 01-17-2024, 05:53 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 for all your help and advise Guessed and Italophile. Without your guidance I'd be still very stuck. Now I have a brilliant functional document to my needs.

Really appreciate your patience and help with this one!
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 08:40 AM.


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