Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2020, 01:13 AM
kyotokisses kyotokisses is offline Modifying Next Paragraph Based on Dropdown Selected Windows 10 Modifying Next Paragraph Based on Dropdown Selected Office 2010
Novice
Modifying Next Paragraph Based on Dropdown Selected
 
Join Date: Apr 2020
Posts: 11
kyotokisses is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 04-24-2020, 06:13 AM
gmayor's Avatar
gmayor gmayor is offline Modifying Next Paragraph Based on Dropdown Selected Windows 10 Modifying Next Paragraph Based on Dropdown Selected Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 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.
Attached Files
File Type: docm Form example.docm (38.8 KB, 16 views)
__________________
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 04-24-2020, 03:26 PM
macropod's Avatar
macropod macropod is offline Modifying Next Paragraph Based on Dropdown Selected Windows 7 64bit Modifying Next Paragraph Based on Dropdown Selected Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #4  
Old 04-26-2020, 01:16 PM
gmaxey gmaxey is online now Modifying Next Paragraph Based on Dropdown Selected Windows 10 Modifying Next Paragraph Based on Dropdown Selected Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
Attached Images
File Type: jpg CXMLPart.jpg (29.8 KB, 30 views)
Attached Files
File Type: docm Form example.docm (73.1 KB, 5 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 04-26-2020, 03:32 PM
macropod's Avatar
macropod macropod is offline Modifying Next Paragraph Based on Dropdown Selected Windows 7 64bit Modifying Next Paragraph Based on Dropdown Selected Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by gmaxey View Post
Paul, downloaded the document from your link and nothing happens when I change the FF DDL. I may be missing something.
Did you exit the formfield via the TAB key after updating it?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 04-26-2020, 03:36 PM
gmaxey gmaxey is online now Modifying Next Paragraph Based on Dropdown Selected Windows 10 Modifying Next Paragraph Based on Dropdown Selected Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Yes, I tried.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 04-26-2020, 04:15 PM
macropod's Avatar
macropod macropod is offline Modifying Next Paragraph Based on Dropdown Selected Windows 7 64bit Modifying Next Paragraph Based on Dropdown Selected Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It's working for me...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 04-26-2020, 08:10 PM
kyotokisses kyotokisses is offline Modifying Next Paragraph Based on Dropdown Selected Windows 10 Modifying Next Paragraph Based on Dropdown Selected Office 2010
Novice
Modifying Next Paragraph Based on Dropdown Selected
 
Join Date: Apr 2020
Posts: 11
kyotokisses is on a distinguished road
Default

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.
Reply With Quote
  #9  
Old 04-26-2020, 09:07 PM
kyotokisses kyotokisses is offline Modifying Next Paragraph Based on Dropdown Selected Windows 10 Modifying Next Paragraph Based on Dropdown Selected Office 2010
Novice
Modifying Next Paragraph Based on Dropdown Selected
 
Join Date: Apr 2020
Posts: 11
kyotokisses is on a distinguished road
Default

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.
Attached Images
File Type: png 1.png (8.8 KB, 25 views)
Reply With Quote
  #10  
Old 04-26-2020, 10:35 PM
macropod's Avatar
macropod macropod is offline Modifying Next Paragraph Based on Dropdown Selected Windows 7 64bit Modifying Next Paragraph Based on Dropdown Selected Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #11  
Old 01-06-2021, 04:32 AM
kyotokisses kyotokisses is offline Modifying Next Paragraph Based on Dropdown Selected Windows 10 Modifying Next Paragraph Based on Dropdown Selected Office 2010
Novice
Modifying Next Paragraph Based on Dropdown Selected
 
Join Date: Apr 2020
Posts: 11
kyotokisses is on a distinguished road
Default

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!
Reply With Quote
Reply

Thread Tools
Display Modes


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
Modifying Next Paragraph Based on Dropdown Selected Assign selected value from DropDown to a variable jhansrod Word VBA 3 06-13-2019 04:46 PM
Modifying Next Paragraph Based on Dropdown Selected 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

Other Forums: Access Forums

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