I have tried Many variants of the code below, but to no avail. It is part of
a UserForm Initialization, designed to change OptionButton2 to true of there
is an X in Text Box 16 of the active document.
ActiveDocument.Shapes("Text Box 16").Select
Selection.ShapeRange.TextFrame.TextRange.Select
If Selection.Text = "X" Then
OptionButton2.Value = True
End If
Hi Patrick,
try
If Selection.Text = "X" & chr(13) Then
Still better not to select anything, like:
Dim s As String
s = ActiveDocument.Shapes(1).TextFrame.TextRange
' shapes(1) is just for my convenience
s = Left(s, Len(s) - 1) ' cut off paragraph mark if you like
if s = .................

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Patrick C. Simonds - 15 Apr 2007 18:30 GMT
Thanks for your help. Here is the final code:
Dim s As String
s = ActiveDocument.Shapes("Text Box 16").TextFrame.TextRange
s = Left(s, Len(s) - 1) ' cut off paragraph mark if you like
If s <> x Then
OptionButton2.Value = True
End If
You also solved another problem I had not begun to address. That was when I
was populating the TextBoxes on my UserForm, I was getting the paragraph
mark:
s = ActiveDocument.Shapes("Text Box 217").TextFrame.TextRange
s = Left(s, Len(s) - 1) ' cut off paragraph mark if you like
TextBox1.Text = s
> Hi Patrick,
>
[quoted text clipped - 9 lines]
> s = Left(s, Len(s) - 1) ' cut off paragraph mark if you like
> if s = .................
Patrick C. Simonds - 15 Apr 2007 18:57 GMT
Is there any way to alter the code so that it can place text into the Text
Box on the document? This would of course be a separate process. The code
you provided was it populate the UserForm during UserForm Initialization,
but it was so clean I am wondering if t would not do better than the code I
came up with to fill in the document. Here is a sample of what I came up
with. As you can see I do not know how to avoid using Select.
If OptionButton2.Value = True Then 'Mrs.
ActiveDocument.Shapes("Text Box 16").Select
Selection.Text = "X"
End If
> Hi Patrick,
>
[quoted text clipped - 7 lines]
> s = Left(s, Len(s) - 1) ' cut off paragraph mark if you like
> if s = .................
Helmut Weber - 15 Apr 2007 19:18 GMT
Hi Patrick,
like this:
ActiveDocument.Shapes(1).TextFrame.TextRange.Text = "X"

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"