any suggestions welcome.
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
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
"everindrummer" <everin...@discussions.microsoft.com> wrote in message
news:7B32488B-B213-4886...@microsoft.com...
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
>> 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
The main problem with a reductive process as you describe, is that of
replacing the deleted paragraphs in the event of a wrong choice - though
this is not insurmountable.
There is a potential issue with docvariable fields, but they will work with
most practical paragraph lengths. If you want the paragraph to be user
editable without the need to edit the macro, you could read the paragraph
into the docvariable from from an external text file. Without exploring the
potential to do that in any depth the following would work.
Or you could use includetext fields. There were some alternative suffestions
in the linked page that could be adapted.
Option Explicit
Private oVars As Variables
Private oFSO As New FileSystemObject
Private oPara As Object
Private sText As String
Private Sub CommandButton1_Click()
Set oVars = ActiveDocument.Variables
Select Case Me.ListBox1.Value
Case Is = "Para 1"
Set oPara = oFSO.OpenTextFile("c:\Para1.TXT")
Case Is = "Para 2"
Set oPara = oFSO.OpenTextFile("c:\Para2.TXT")
Case Is = "Para 3"
Set oPara = oFSO.OpenTextFile("c:\Para3.TXT")
End Select
sText = ""
Do Until oPara.AtEndOfStream
sText = sText & oPara.ReadLine
Loop
oVars("varPara").Value = sText
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
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
"Fumei2 via OfficeKB.com" <u53619@uwe> wrote in message
news:a50fb0fe38b6e@uwe...
Option Explicit
Private oVars As Variables
Private oFSO As New FileSystemObject
Private oPara As Object
Private sText As String
Private sFname As String
Private iCount As Integer
Private Sub CommandButton1_Click()
Set oVars = ActiveDocument.Variables
iCount = Me.ListBox1.ListIndex + 1
sFname = "c:\Para" & iCount & ".txt"
Set oPara = oFSO.OpenTextFile(sFname)
sText = ""
Do Until oPara.AtEndOfStream
sText = sText & oPara.ReadLine & vbCr
Loop
sText = Left(sText, Len(sText) - 1)
oVars("varPara").Value = sText
ActiveDocument.Fields.Update
Unload Me
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.Clear
.AddItem "Para 1"
.AddItem "Para 2"
.AddItem "Para 3"
.ListIndex = 0
End With
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
"Graham Mayor" <gma...@REMOVETHISmvps.org> wrote in message
news:Ou2vxqNx...@TK2MSFTNGP04.phx.gbl...
> Yes you could do it that way, but I guess approach is a matter of
> preference. Mine is to use the macro to add text as required :)
>
> The main problem with a reductive process as you describe, is that of
> replacing the deleted paragraphs in the event of a wrong choice - though
> this is not insurmountable.
>
> There is a potential issue with docvariable fields, but they will work
> with most practical paragraph lengths. If you want the paragraph to be
> user editable without the need to edit the macro, you could read the
> paragraph into the docvariable from an external text file. Without