#1
|
|||
|
|||
Need help with userform and radio buttons
Hi there working on a word document and having some issues with some quality of life functions.
The document uses a userform where the user inputs some base data and then the userform fills it into the right areas in the document. There is also some different choices available for the user to check using radio buttons. They each hide certain text depending on the radio button chosen. So far it all works as expected but I am having issues when users reopen the document after saving. The radio buttons are blank and have to be pressed again. This requires the user recheck them again and increases the risk of chosing the wrong stuff or forgetting pressing them. Now I know this is the way radio buttons work but I am wondering if there is a way to make them be pre selected depending on what text within a certain bookmark is hidden or not in the document. tried the follwing within userform_Activate () With ActiveDocument If ActiveDocument.Bookmarks("LJSidor1").Range.Font.Hi dden = True Then Me.LJNejKnapp = True Else Me.LJJaKnapp = True End If End With Where "LJSidor1" is one of the bookmarks that hides a certain part of the document depending on the choice of the "LJNejKnapp" button or "LJJaKnapp" button. Is it possible to do something like this or am I wasting my time, is there any other way to accomplish the same thing? Any help would be appriciated ! //john |
#2
|
|||
|
|||
One way I use to save the state of controls on the user form is to save them as document variable whenever the user form is hidden or unloaded. Is there another way to save, then to the Windows registry, but I'd rather save inside the document only.
The code is not working? Is there a error message?:
__________________
Backup your original file before doing any modification. |
#3
|
|||
|
|||
There is no error message from the code above but it always defaults to Me.LJJaKnapp = True now. So the first if part seems to not be correct / do anything.
Guess I will have to look up your tip there since I have no idea what that is or how to do it! |
#4
|
|||
|
|||
Quote:
I would suggest that the user form initialisation event is the best place for your code. Code:
Private Sub UserForm_Initialize() ' for each bookmark you need a line of code similar to Me.LJNejKnapp = ActiveDocument.Bookmarks("LJSidor1").Range.Font.Hidden ' which assumes that if hidden = true then you want Me.LJNejKnapp also to be true ' if you want the opposite then put a 'Not' before Active document ' e.g. Me.LJNejKnapp = Not ActiveDocument.Bookmarks("LJSidor1").Range.Font.Hidden ' If your radio buttons are grouped, so that selecting one automatically switches the others in the groups to off ' you only need one of the lines above per group. End Sub |
#5
|
||||
|
||||
Try the following
Code:
Private Sub UserForm_Activate() Dim oBM As Bookmark With ActiveDocument If .Bookmarks.Exists("LJSidor1") = True Then Set oBM = .Bookmarks("LJSidor1") If oBM.Range.Font.Hidden = True Then MsgBox "hidden" LJNejKnapp.value = True Else MsgBox "not hidden" LJJaKnapp.value = True End If Else MsgBox "missing" LJNejKnapp.value = False LJJaKnapp.value = False End If End With End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
radio button, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Radio Buttons in Word Document in MAC Office 2016 | kim88 | Word | 3 | 12-19-2016 03:36 PM |
Radio buttons in a particular page gets disabled when i scroll down and return back to that page. | arnprd | Word | 0 | 06-18-2015 10:54 AM |
check box issue (problem with radio buttons from web page) Word 2013 | cQQlgirl | Word | 6 | 03-19-2015 07:23 PM |
Performance problem ActiveX radio buttons | NobodysPerfect | Word VBA | 8 | 05-31-2014 03:51 AM |
example of radio buttons in for data entry? | derohanes | Excel | 1 | 03-05-2011 09:37 AM |