Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2020, 12:52 AM
4Star1957 4Star1957 is offline Message box to input a value Windows 10 Message box to input a value Office 2016
Novice
Message box to input a value
 
Join Date: Sep 2020
Posts: 12
4Star1957 is on a distinguished road
Cool Message box to input a value

Hello I have a very large document. When the document is opened I want a dialogue/message box to appear and into it the user will put a value 1-4. Each value has different paragraphs required. What I plan on doing say if 2 is selected when the file is opened - a macro will run and delete bookmarked text for input value 1, 3 and 4.
Would this be workable? Would I be better off using a dependent dropdown? thank you
Reply With Quote
  #2  
Old 09-14-2020, 01:28 AM
Guessed's Avatar
Guessed Guessed is online now Message box to input a value Windows 10 Message box to input a value Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

Yes it would be workable but not particularly flexible. You can only use a bookmark name once so if there are multiple places to remove content then it would require lots of code. Also if the user makes the wrong choice there is no coming back without restarting the doc. I would hide text to make it non-destructive in the event of a bad selection - this does require the user's options set to not show hidden text.

I would be more inclined to use Content Controls and either the Tag or Title property on the dependent text so you can affect more than one text area. If the selection is allowed to show in the document then it could be used instead of a code-based dialog box.

As an example, set up your doc with a dropdown Content Control titled Salesperson and then a bunch of Content Controls which use a title corresponding to one of those entries in Salesperson then code to hide CCs which don't have that title is
Code:
Private Sub Document_ContentControlOnExit(ByVal myCC As ContentControl, Cancel As Boolean)
  Dim aCC As ContentControl, sSales As String
  If myCC.Title = "Salesperson" Then
    sSales = myCC.Range.Text
    For Each aCC In ActiveDocument.ContentControls
      aCC.Range.Font.Hidden = aCC.Title <> sSales  'hide if CC title doesn't match selected salesperson
    Next aCC
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 09-14-2020, 01:46 AM
4Star1957 4Star1957 is offline Message box to input a value Windows 10 Message box to input a value Office 2016
Novice
Message box to input a value
 
Join Date: Sep 2020
Posts: 12
4Star1957 is on a distinguished road
Default Reply

Apology if I'm replying incorrectly. Thank you "Guessed" for your reply and your suggestion to use CC sounds very good, only I've very basic knowledge of CC. Just to explain further, the document is very large, 30 + pages, it is an employment agreement for full time, part time and casual employees. Each employment type has different paragraphs to be inserted throughout the document. I do like the sound of a dropdown - that would be for each employment type, when the employment type is selected all relevant paragraphs will be presented throughout and those not relevant would be hidden? Is is going to be difficult for me? Is there somewhere I can get say sample code of how I would proceeds with this? Thank you for your response.
Reply With Quote
  #4  
Old 09-14-2020, 03:21 AM
Guessed's Avatar
Guessed Guessed is online now Message box to input a value Windows 10 Message box to input a value Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

You already have sample code but if you want a working sample, then you need to add a Dropdown Content Control titled "EmploymentType". Give it three entries for "Full time", "Part time" and "Casual"

Then select the text that only appears if Full time is selected and click the Plain Text CC button on your Developer Tab. Change the title of that CC to "Full time". Do the same for any other instances that need to be visible when Full time is selected.

Do the same for the Part time and Casual sections of text.

Put this code in your ThisDocument module.
Code:
Private Sub Document_ContentControlOnExit(ByVal myCC As ContentControl, Cancel As Boolean)
  Dim aCC As ContentControl, sET As String
  If myCC.Title = "EmploymentType" Then
    sET = myCC.Range.Text
    For Each aCC In ActiveDocument.ContentControls
      aCC.Range.Font.Hidden = aCC.Title <> sET  'hide if CC title doesn't match selected employment type
    Next aCC
  End If
End Sub
Save the document as docm or dotm. You should be able to make a selection on the dropdown CC and see the changes as soon as you move your selection out of that CC.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 09-14-2020, 04:04 AM
4Star1957 4Star1957 is offline Message box to input a value Windows 10 Message box to input a value Office 2016
Novice
Message box to input a value
 
Join Date: Sep 2020
Posts: 12
4Star1957 is on a distinguished road
Default Confirmation of correct code

Hi Guessed, apology for querying again, could you please confirm I have the correct code below. I have put together a little test doc to test how it works. I created a content control dropdown, named it "EmploymentType". I created three options for the dropdown "Full time", "Part time" and "Casual". I then created plain text content control paras titling a couple "Full time" "Part time" "casual". I then copied your code to "this document" in VB. I also saved the document as a docm. Have I renamed the code correctly Guessed. I appreciate your assistance, apology I am new to this.

Private Sub Document_ContentControlOnExit(ByVal myCC As ContentControl, Cancel As Boolean)
Dim aCC As ContentControl, sET As String
If myCC.Title = "Full Time" Then
sET = myCC.Range.Text
For Each aCC In ActiveDocument.ContentControls
aCC.Range.Font.Hidden = myCC.Title <> sET 'hide if CC title doesn't match selected employment type
Next aCC
End If

If myCC.Title = "Part Time" Then
sET = myCC.Range.Text
For Each aCC In ActiveDocument.ContentControls
aCC.Range.Font.Hidden = myCC.Title <> sET 'hide if CC title doesn't match selected employment type
Next aCC
End If

If myCC.Title = "Casual" Then
sET = myCC.Range.Text
For Each aCC In ActiveDocument.ContentControls
aCC.Range.Font.Hidden = myCC.Title <> sET 'hide if CC title doesn't match selected employment type
Next aCC
End If

End Sub
Reply With Quote
  #6  
Old 09-14-2020, 04:32 AM
gmayor's Avatar
gmayor gmayor is offline Message box to input a value Windows 10 Message box to input a value 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

Don't use SET as a string variable name. SET is a reserved command name in VBA and will produce an error if used in this way Charge it to sSet of strSet.

Note also that content control titles are case sensitive so if the CC is called "Full time" the VBA needs to address it in the same way.

Personally I don't like the use of hidden text except perhaps in a document the final version of which will be distributed either printed or as PDF. I prefer to fill content controls with the appropriate texts based on the selected value.
__________________
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
  #7  
Old 09-14-2020, 04:35 AM
4Star1957 4Star1957 is offline Message box to input a value Windows 10 Message box to input a value Office 2016
Novice
Message box to input a value
 
Join Date: Sep 2020
Posts: 12
4Star1957 is on a distinguished road
Default

Thank you Graham, but I'm not sure what to use in place of "Set".
I will check your tips out and see if I can find my answer there.
Reply With Quote
  #8  
Old 09-14-2020, 05:06 AM
Guessed's Avatar
Guessed Guessed is online now Message box to input a value Windows 10 Message box to input a value Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

You didn't need to change my code other than to change the sET to something else eg strET.

The dropdown Content Control needs the title EmploymentType

As Graham says, hiding content is problematic if you are sending docs to other people without converting to PDF first. If you get it working as it is, I can explain how to permanently delete the hidden content.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #9  
Old 09-14-2020, 05:33 AM
4Star1957 4Star1957 is offline Message box to input a value Windows 10 Message box to input a value Office 2016
Novice
Message box to input a value
 
Join Date: Sep 2020
Posts: 12
4Star1957 is on a distinguished road
Default

Hey Guessed, I have got it working although it is not correct. Everything goes into hidden text. I did change the sSET to what Graham suggested.
I propose if I can get this going to create a macro to delete all hidden text.
Any suggestions as to why everything turns to hidden text? I have checked that the names are all consistent within the VB code and the content controls.

Also which I find a bit strange, even though the content control text is in hidden text (I can tell because of the dotted line underneath the text) - I can see it on the screen even though I have selection in File/Options do not show hidden text (box unticked).

Here is the current code placed in "this document" :

Private Sub Document_ContentControlOnExit(ByVal myCC As ContentControl, Cancel As Boolean)
Dim aCC As ContentControl, strSet As String
If myCC.Title = "Full Time" Then
strSet = myCC.Range.Text
For Each aCC In ActiveDocument.ContentControls
aCC.Range.Font.Hidden = aCC.Title <> strSet 'hide if CC title doesn't match selected employment type
Next aCC
End If

If myCC.Title = "Part Time" Then
strSet = myCC.Range.Text
For Each aCC In ActiveDocument.ContentControls
aCC.Range.Font.Hidden = aCC.Title <> strSet 'hide if CC title doesn't match selected employment type
Next aCC
End If

If myCC.Title = "Casual" Then
strSet = myCC.Range.Text
For Each aCC In ActiveDocument.ContentControls
aCC.Range.Font.Hidden = aCC.Title <> strSet 'hide if CC title doesn't match selected employment type
Next aCC
End If

End Sub

thank you for your assistance, sorry about keep coming back - I think the error is something very simple, but I'm unable to see it.
Reply With Quote
  #10  
Old 09-14-2020, 06:27 AM
Guessed's Avatar
Guessed Guessed is online now Message box to input a value Windows 10 Message box to input a value Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

You changed my code. If I meant for you to edit all the code I would have created it that way.

Look back at the code I provided and try to understand what it is doing.

Or post your document so I can fix up the changes to align with your Content Controls.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #11  
Old 09-14-2020, 06:42 AM
4Star1957 4Star1957 is offline Message box to input a value Windows 10 Message box to input a value Office 2016
Novice
Message box to input a value
 
Join Date: Sep 2020
Posts: 12
4Star1957 is on a distinguished road
Default

Hey Guessed, thank you for offering to take a look at this and hopefully fix. This file is very small - I wanted to see it working before I started the process on the large doc. Thank you.
Attached Files
File Type: dotm Test.dotm (26.5 KB, 5 views)
Reply With Quote
  #12  
Old 09-14-2020, 07:18 AM
Guessed's Avatar
Guessed Guessed is online now Message box to input a value Windows 10 Message box to input a value Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

Replace the code in the ThisDocument module with this
Code:
Private Sub Document_ContentControlOnExit(ByVal myCC As ContentControl, Cancel As Boolean)
  Dim aCC As ContentControl, strSet As String
  If myCC.Title = "EmploymentType" Then
    strSet = myCC.Range.Text
    For Each aCC In ActiveDocument.ContentControls
      If aCC.Title <> "EmploymentType" Then
        aCC.Range.Font.Hidden = aCC.Title <> strSet  'hide if CC title doesn't match selected employment type
      End If
    Next aCC
  End If
  ActiveWindow.View.ShowAll = False
  ActiveWindow.View.ShowHiddenText = False
End Sub
Attached Files
File Type: dotm Test.dotm (27.3 KB, 6 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #13  
Old 09-14-2020, 03:00 PM
4Star1957 4Star1957 is offline Message box to input a value Windows 10 Message box to input a value Office 2016
Novice
Message box to input a value
 
Join Date: Sep 2020
Posts: 12
4Star1957 is on a distinguished road
Default

Thank you Guessed - that worked great. There is a lot of space where the text was converted to hidden text. Is it possible for a macro to automatically run to delete the hidden text once the dropdown has done its job?

Thank you again.
Reply With Quote
  #14  
Old 09-14-2020, 03:07 PM
Guessed's Avatar
Guessed Guessed is online now Message box to input a value Windows 10 Message box to input a value Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

The space is appearing because the text is inside the Content Control but the paragraph mark is not.
You could remove the trailing paragraph marks to position all three CCs consecutively in the same paragraph (only one appears at a time)
Or
Convert the plain text CCs into Rich Text CCs which do allow the paragraph mark to be inside the CC.

The way you do it in your final doc depends on the layout you are trying to achieve.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #15  
Old 09-14-2020, 05:04 PM
4Star1957 4Star1957 is offline Message box to input a value Windows 10 Message box to input a value Office 2016
Novice
Message box to input a value
 
Join Date: Sep 2020
Posts: 12
4Star1957 is on a distinguished road
Default

Hi Guessed, I am getting an error message which I've attached. It will work sometimes but mostly I will get the attached dialogue error.

Converting the plain text to rich text may be a bit cumbersome? Not sure. The doc will be used by basic word users.

Can you or someone else suggest another method I could try to get this going please? Note that each selection on the dropdown contains about 35 pages.

Thank you.
Attached Images
File Type: jpg Error Dialogue on Full Time.JPG (31.8 KB, 16 views)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Custom Form in Outlook 2016, for the Message setting 'Do not include original message' jsvictor1989@gmail.com Outlook 0 01-30-2019 10:54 PM
trouble with input box gummybear Excel Programming 0 12-04-2018 06:39 AM
Need Help on Input Video into PPT agus PowerPoint 2 07-13-2015 02:25 AM
Message box to input a value Message replys are shown at the bottom of the message, how can I get them to the top Gardy Outlook 3 05-23-2012 01:20 AM
Message box to input a value Input Box ubns Word 2 04-13-2012 06:28 AM

Other Forums: Access Forums

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