Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-10-2016, 11:57 AM
Anandpersad Anandpersad is offline Hiding and unhiding text based on text dropdown button Windows 10 Hiding and unhiding text based on text dropdown button Office 2013
Novice
Hiding and unhiding text based on text dropdown button
 
Join Date: May 2016
Location: Drunen, The Netherlands
Posts: 2
Anandpersad is on a distinguished road
Default Hiding and unhiding text based on text dropdown button

Hi All,

I am using MS Word 2010


I am looking for a VBA in word for the following issue:
I have the following dropdown button, with the options: Yes and No. Name of the dropdown box is choose.

In case yes is choses I want the VBA to hide row 13+14 in word. If No is chosen than unhide row 13+14 in word.
Thanks in advance for your help.

Anand
Reply With Quote
  #2  
Old 05-10-2016, 01:37 PM
macropod's Avatar
macropod macropod is offline Hiding and unhiding text based on text dropdown button Windows 7 64bit Hiding and unhiding text based on text dropdown button Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

What kind of dropdown, what kind of rows and where are they?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-11-2016, 05:51 AM
Anandpersad Anandpersad is offline Hiding and unhiding text based on text dropdown button Windows 10 Hiding and unhiding text based on text dropdown button Office 2013
Novice
Hiding and unhiding text based on text dropdown button
 
Join Date: May 2016
Location: Drunen, The Netherlands
Posts: 2
Anandpersad is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
What kind of dropdown, what kind of rows and where are they?
Hi Paul,

It is drop down list, created through Drop-Down list Contend Control (Developer).

With rows I meant lines in a word documnent. Lines 13+14 in the word document.

The drop-down and the lines are in the same word document.

In the first page you make your choices, with the drop down buttons.

The text below should hidden / unhidden based on the choices you made.

Thanks and Regards,

Anand
Reply With Quote
  #4  
Old 08-25-2016, 01:31 AM
gmayor's Avatar
gmayor gmayor is offline Hiding and unhiding text based on text dropdown button Windows 10 Hiding and unhiding text based on text dropdown button Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
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

What you ask is not as straightforward as you envisage. For a start 'Line' is a vague concept in Word and is determined by text flow.

If I was doing this I would do it differently. I would start with a bookmark inserted at the location where the text is to appear (or disappear). Name the bookmark (say) BMPara13

Save the text you want to display/hide as an autotext entry in the document template and call it Para13.

In the ThisDocument module add the code

Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    Select Case ContentControl.Title
        Case "SelectPara"
            If ContentControl.Range.Text = "No" Then
                BBToBM "BMPara13", ThisDocument.AttachedTemplate, "Para13"
            Else
                FillBM "BMPara13", ""
            End If
        Case Else
            'The user exited some other content control that we don't care about.
    End Select
lbl_Exit:
    Exit Sub
End Sub
Then whenever you leave the content control, you will either insert or remove the autotext entry at/from the bookmarked location.

The code above calls upon a pair of functions to insert/remove the autotext

Code:
Public Sub FillBM(strBMName As String, strValue As String)
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set oRng = .Bookmarks(strBMName).Range
        oRng.Text = strValue
        oRng.Bookmarks.Add strBMName
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub

Public Sub BBToBM(strBMName As String, strTemplate As String, strBBName As String)
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
Dim iLen1 As Integer, iLen2 As Integer
    With ActiveDocument
        iLen1 = Len(ActiveDocument.Range)
        On Error GoTo lbl_Exit
        Set oRng = .Bookmarks(strBMName).Range
        Application.Templates(strTemplate). _
                BuildingBlockEntries(strBBName).Insert _
                Where:=oRng, _
                RichText:=True
        iLen2 = Len(ActiveDocument.Range)
        oRng.End = oRng.End + (iLen2 - iLen1)
        oRng.Bookmarks.Add strBMName
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
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
Reply

Tags
vba code, word 2010



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding and unhiding text based on text dropdown button Hiding text and macro security subspace3 Word VBA 4 10-05-2014 10:01 AM
Word Macro for hiding text Phil Pense Word 1 07-23-2012 08:17 PM
Hiding and unhiding text based on text dropdown button Mark text in a text box and copy to clipboard (with button) ArthurM PowerPoint 4 02-19-2012 11:33 AM
Macro to populate a text form field based on dropdown selection koloa Word 0 10-20-2011 11:52 AM
Hiding text Reg06 Visio 0 01-15-2011 08:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:50 PM.


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