I'm creating an MS Word document with a table at the top with cells for 'Name', 'Date', 'Skills Verified' etc. and 10 questions in separate sections below this.
I'm creating a UserForm to make it simpler for all participants to complete the assessment on their PC's.
I'm using a MultiPage to show each question on a separate page of the UserForm and to display the question I'm attempting to populate the Caption of a Label by referencing the question on the document using an enclosed bookmark.
Please note: Other staff may edit or manage this document in future and most of them are not experienced at all with VBA or UserForms which is the main focus for what I'm attempting (plus it's efficient right?).
I've read up on bookmarks (wordmvp) and I understand how to set the bookmarks fine.
I can't work out how to get the contents of an enclosed bookmark to populate the Label Caption on UserForm initialization.
I've looked at the following info but haven't been able to make any sense of it. https://msdn.microsoft.com/en-us/vba/word-vba/articles/bookmarks-object-word https://msdn.microsoft.com/en-us/vba/word-vba/articles/captionlabels-object-word https://forum.solidworks.com/thread/209704
Assuming default names are used in the UserForm and the question "Is this a test question?" is in an enclosed bookmark named "bookmark1" in my document; below is the closest working code I could come up with.
Private Sub UserForm_Initialize()
Dim question1 As String
question1 = ActiveDocument.Bookmarks("bookmark1")
With Selection
Label1.Caption = question1
End With
End Sub
However this displays the string "bookmark1" in the label1 caption, not "Is this a test question?".
I can't work out how to edit the code to make it show the text from the bookmark rather than the string "bookmark1" in the label1 caption (I'm not even sure if it's possible?).
Can anyone share where I've gone wrong and explain how to amend this?
Label1.Caption = Selection
instead ofLabel1.Caption = question1
? – Vityataquestion1 = ActiveDocument.Bookmarks("bookmark1").Range.Text
? – PeterT