Log in

View Full Version : Link document text to userform



sharky12345
06-13-2013, 03:11 AM
Is there a way I can link the full text of a document to a userform so that it can be edited from within the form like you can with Excel?

It doesn't have to be a textbox, although that would be the obvious choice if it is possible.

gmaxey
06-13-2013, 06:57 AM
You and load a textbox with a storyrange text (e.g., the maintext story):

Private Sub UserForm_Initialize()
TextBox1.Text = ActiveDocument.Range.Text
End Sub

sharky12345
06-13-2013, 07:02 AM
Thanks Greg - tried that but the box is blank and I can't type anything in it.

Would it make any difference if the document is a template with bookmarks?

gmaxey
06-13-2013, 07:06 AM
Don't know what to say. That code works fine here.

sharky12345
06-13-2013, 07:28 AM
I've tried it with a new document and it does work so I'll work on it - the textbox does show the little paragraph marks, do you know of a way to omit those?

gmaxey
06-13-2013, 07:31 AM
Set textbox property multiline to true.

sharky12345
06-13-2013, 07:34 AM
Thanks!

sharky12345
06-13-2013, 08:05 AM
Greg, a final one if I may please?

I can't seem to get the vertical scrollbar to start at the top - can it be done?

gmaxey
06-13-2013, 12:49 PM
Private Sub UserForm_Initialize()
With TextBox1
.Text = ActiveDocument.Range.Text
.MultiLine = True
.ScrollBars = fmScrollBarsVertical
.SetFocus
.SelStart = 0
End With
End Sub

sharky12345
06-14-2013, 09:26 AM
Thank you again!