![]() |
#1
|
|||
|
|||
![]()
Hi,
in fact I have 2 requests : I have a text with 10 chapters First, I need to have 10 checkbox to choice which chapters I need to show in the final document. Secondly, those chapters need to have fields that will be completed with informations contained in a table located in the top of the first page. is it possible to do something like that in Word VBA ? Is someone can share part of code ? Thanks a lot |
#2
|
||||
|
||||
![]()
If you bookmark the chapters and title the checkboxes (as in the attached) and run the macro, it will create a document with those checked chapters with the text replaced from the table.
If you add to or change the texts ensure the content control and bookmark naming is maintained. If you want the new document to have consecutively numbered chapters then you will need to set a counter and replace the number (i.e. remove the apostrophes from the commented out section).
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Thanks a lot for your code.
I'haven't really well understand what you explain here : Quote:
ie ------------------------------------ Chapter 1 - Choiced by checkbox ------------------------------------ Chapter 3 - Choiced by checkbox ------------------------------------ --------- to------------------------ ------------------------------------ Chapter 12 - Choiced by checkbox ------------------------------------ End of the doc - on every document, not need to checkbox ------------------------------------ And lastly, how to put a condition that chapter 1 and/or 2 need to be checked to validate the document ? it's really a great help, thanks a lot, you're writing VBA like you speak. It's not so easy for me. Martial |
#4
|
||||
|
||||
![]()
If you look at the main macro, you will see a section that appears green coloured. That code is commented out and does nothing. If you remove the apostrophes from the start of each green coloured line that code will be run along with the rest of the macro to renumber the chapters.
To add your fixed code (which should be bookmarked in the source template also) locate the line Code:
Next oCC Code:
'Add this code Set oRng = oDoc.Range oRng.Collapse 0 oRng.FormattedText = oSource.Bookmarks("The name of the bookmark with the fixed text").Range.FormattedText
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
![]()
I let this message, but see the update in the next one.
Great and quick answer, that's work well ! I tried by myself to add introduction text at the top of document by adding your code with some modification, but nothing appears even there is no error. The introduction part have the bookmark name bmStartChapter. I put this code just after the Dim list section Code:
'Add introduction text at the beginning Set oSource = ThisDocument Set oDoc = Documents.Add(oSource.FullName) Set oRng = oDoc.Range oRng.Collapse 0 oRng.FormattedText = oSource.Bookmarks("bmStartChapter").Range.FormattedText |
#6
|
|||
|
|||
![]()
I found my error
In fact I need to put the code after the line : Code:
oDoc.Range.Text = "" ![]() Any ideas how to put this condition that chapter 1 and/or 2 need to be checked to validate the document ? Without this condition, the macro send a message. Thanks, I learn quickly with you. |
#7
|
||||
|
||||
![]()
The code uses the source template to create the new document and the
Code:
oDoc.Range.Text = "" If you need Chapter 1 and Chapter 2 to be included always, the simplest approach is to check the two check boxes and change their properties to check the option 'Contents cannot be edited'. Then they cannot be changed from the template. The lines Code:
Else MsgBox "No checkboxes were checked"
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#8
|
|||
|
|||
![]()
Thanks, everything works well
Quote:
To validate the document, One of them or both must be checked. Thanks |
#9
|
||||
|
||||
![]()
In that case add the following immediately after the Set oSource = ThisDocument line
Code:
If oSource.SelectContentControlsByTitle("Chapter1").Item(1).Checked = False And _ oSource.SelectContentControlsByTitle("Chapter2").Item(1).Checked = False Then MsgBox "Chapter 1 and/or Chapter 2 must be selected" GoTo lbl_Exit End If
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#10
|
|||
|
|||
![]()
You're the one, thanks a lot
![]() I have separated in 2 check,
After Code:
Set oSource = ThisDocument Code:
'test si les chapter 1 ou 2 sont cochés If oSource.SelectContentControlsByTitle("Chapter1").Item(1).Checked = False And _ oSource.SelectContentControlsByTitle("Chapter2").Item(1).Checked = False Then MsgBox "Les cases 1 ou 2 doivent être cochées" GoTo lbl_Exit End If 'test si les chapter 1 et 2 sont cochés If oSource.SelectContentControlsByTitle("Chapter1").Item(1).Checked = True And _ oSource.SelectContentControlsByTitle("Chapter2").Item(1).Checked = True Then MsgBox "Les cases 1 et 2 ne doivent pas être cochées ensemble" GoTo lbl_Exit End If |
#11
|
|||
|
|||
![]()
Hello, excuse me, but how did you create the arrow which shows and close the chapter? I sign it in green round.
Thank you in advance |
#12
|
||||
|
||||
![]()
The 'arrow' appears when you hover your cursor over a paragraph to which a heading style has been applied. It is a built-in Word indicator.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#13
|
|||
|
|||
![]() Quote:
I can't find it. Where is that "arrow"? Where is word indicator located? |
#14
|
||||
|
||||
![]()
It is built into the heading styles. Chapter 1 has a heading style applied to it. If you hover the cursor over the paragraph with that style it will appear for the duration that the cursor is present.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#15
|
|||
|
|||
![]() Quote:
![]() Thank you so much!) |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Bookmark will not show/hide based on CC Checkbox | lord_kaiser | Word VBA | 1 | 04-17-2018 01:19 AM |
![]() |
namrehx | Word VBA | 16 | 12-14-2017 01:45 PM |
How to use checkbox to show and hide bookmarked text? | namrehx | Word VBA | 1 | 12-12-2017 02:17 PM |
![]() |
derajlance | Word VBA | 1 | 05-13-2016 01:55 PM |
![]() |
tammytran105 | Word VBA | 7 | 10-02-2014 04:30 PM |