#1
|
|||
|
|||
Modifying Next Paragraph Based on Dropdown Selected
Hi all, I'm relatively new to VBA and am trying to create a locked form which will look something like this. 1. [Topic] [Dropdown: (1) Applies; (2) Does not apply] [Paragraph of text] - if Applies is selected, to retain existing formatting. If Does not apply is selected, to strikethrough whole paragraph. Is there any macro which may be able to do this? Changes are not allowed in the contents in the paragraph and the document will be locked with other form field sections. Thank you. |
#2
|
||||
|
||||
You could do something like the attached. You cannot alter the texts or delete them without changing the properties of the content controls and if you select as you suggested the text is struck through, when you click outside the list box.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
See, for example: https://www.msofficeforums.com/word/...html#post46429
No VBA code required. The conditional content may include multiple paragraphs, pictures, tables, etc. Graham's example uses content controls, but your post indicates you're using formfields. Content controls and formfields shouldn't be used in the same document. They weren't designed to be used that way and doing so is a known source of problems.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Graham,
Things are slow. So just providing this as another example of the CC BeforeStoreUpdate Event. It takes a bit of work to setup but eliminates the need to exit the CC after making the selection. Create three Paragraph1 CCs with the same text. Tag 1 "Paragraph1", Tag 2 "Paragraph1_Norm" and Tag 3 "Paragraph1_ST" Then set the font in "Paragraph1_ST" as strikethrouh. Now map the Topic_1 and three associated Paragraph1 CCs to a CXMLPart (see image). After that you can delete the "Paragraph1_Norm" and "Paragraph1_ST" CCs from the document. Here is the needed code: Code:
Private Sub Document_ContentControlBeforeStoreUpdate(ByVal CC As ContentControl, Content As String) Dim oNode As CustomXMLNode, oNodeC As CustomXMLNode Select Case CC.Title Case Is = "Topic 1" Set oNode = CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Paragraph1[1]") If Content = "Does Not Apply" Then Set oNodeC = CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Paragraph1_ST[1]") Else Set oNodeC = CC.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Paragraph1_Norm[1]") End If oNode.Text = oNodeC.Text End Select lbl_Exit: Exit Sub End Sub BREAK Paul, downloaded the document from your link and nothing happens when I change the FF DDL. I may be missing something. |
#5
|
||||
|
||||
Did you exit the formfield via the TAB key after updating it?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Yes, I tried.
|
#7
|
||||
|
||||
It's working for me...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Hi all,
Thank you for sharing. They both work for me but macropod, I just noticed that some of the paragraphs have numbering between them and conditional formatting does not seem to work well with those paragraphs. However, this is still useful for my other templates. |
#9
|
|||
|
|||
Sorry, just encountered a couple more issues.
I have a few paragraphs that are sub-paragraphs. These may or may not be applicable in its entirety, or applicable with only certain parts of the sub-para to be struck through, and with comment to be inserted. (Refer to attachment for example). Is there anyway I can do a dropdown para specifically for this without the dropdown showing on print, with strikethrough on the points that are not applicable? Separately, is there a way for me to insert a table into a content control field to do exactly the same as per my initial query? I'm getting an error of a 'floating object' which I believe to be the table. |
#10
|
||||
|
||||
Diagnosing the issue would be much simpler if you could attach a document to a post with some representative content. You can do so via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
I'm so sorry I completely overlooked this. We ended up doing a refreshment of the document to move all the optional items to a different document so this was not required anymore. Thank you very much for the help!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro - Copying and Pasting selected slides (based on selected keywords/criteria) Hi | erickhawe | PowerPoint | 0 | 08-16-2019 09:00 PM |
Assign selected value from DropDown to a variable | jhansrod | Word VBA | 3 | 06-13-2019 04:46 PM |
Modifying Paragraph Spacing Issue | cmf0106 | Word | 4 | 03-18-2014 04:12 PM |
Display paragraph of text based on value selected in combo | WordWaza | Word | 0 | 08-09-2013 06:30 AM |
Change cell color everytime a value is selected in dropdown list | angelica_gloria | Excel | 4 | 01-27-2012 06:47 PM |