"It would be simpler to allow the user to pick which paragraph to use
then
enter that paragraph."
Hmmm. While I am not totally disagreeing, I would say this is debatable.
I
think it is equally valid to use an reductive process, rather than
additive
process.
If the there paragraphs are bookmarked, you can use option buttons in a
frame
(thus only being able to choose one). Whatever option is TRUE (that
bookmark
is retained), the others are removed.
Private Sub CommandButton1_Click()
If optPara1.Value = True Then
ActiveDocument.Bookmarks("para2").Range.Delete
ActiveDocument.Bookmarks("paar3").Range.Delete
GoTo MyExit:
End If
If optPara2.Value = True Then
ActiveDocument.Bookmarks("para1").Range.Delete
ActiveDocument.Bookmarks("para3").Range.Delete
GoTo MyExit
End If
If optPara3.Value = True Then
ActiveDocument.Bookmarks("para1").Range.Delete
ActiveDocument.Bookmarks("para2").Range.Delete
Exit Sub
End If
MyExit:
Unload Me
End Sub
The advantage of this is that if the userform is called when you invoke
the
template (Document_New), you end up with the appropriate paragraph, PLUS
you
have free rein to edit the original text in the template. You have no
restriction as to size, as the text content is not hard coded.
oVars("varPara").Value = "The text of Paragraph 1"
This puts actual text into the DOCVARIABLE. What if the paragraph is
very
long? Using the reductive bookmark route means the actual content is not
relevant. If the content is changed, change it in the actual
document/template. No need to edit the code. Plus if the "chunk" is now
a
couple of paragraphs (or even includes a graphic), it makes no difference
as
long as it is within the range of the bookmarks.
Just a thought.
Gerry
Graham said:
It would be simpler to allow the user to pick which paragraph to use then
enter that paragraph.
Use a list box to display sufficient information to choose which
paragraph
Here using the Text Para1 to 3. Given default names for the userform,
list
box and command button, the code associated with the userform could be
similar to the following. Put a docVariable field {DocVariable varPara}
in
the document to display the selected paragraph text.. See also
http://www.gmayor.com/SelectFile.htm
Option Explicit
Private oVars As Variables
Private Sub CommandButton1_Click()
Set oVars = ActiveDocument.Variables
Select Case Me.ListBox1.Value
Case Is = "Para 1"
oVars("varPara").Value = "The text of Paragraph 1"
Case Is = "Para 2"
oVars("varPara").Value = "The text of Paragraph 2"
Case Is = "Para 3"
oVars("varPara").Value = "The text of Paragraph 3"
End Select
ActiveDocument.Fields.Update
Unload Me
End Sub
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem "Para 1"
Me.ListBox1.AddItem "Para 2"
Me.ListBox1.AddItem "Para 3"
End Sub
hi, hope you can help. Im trying to create a document for work, and ive
been
[quoted text clipped - 8 lines]
any suggestions welcome.
--
Gerry
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201003/1