Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Problem with UserForm Initialization

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick C. Simonds - 15 Apr 2007 04:59 GMT
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
Helmut Weber - 15 Apr 2007 08:24 GMT
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"

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.