Word VBA >> select text and assign to variable

by fitful_thought » Sun, 08 Aug 2004 06:59:22 GMT

My document has four lines of text.
Each line ends with a paragraph mark.
How do I select the first line and assign it to string variable sItem1
select the second line and assign it to string variable sItem2
select the third line and assign it to string variable sItem3
select the fourth and assign it to string variable sItem4?

I'm new to vba for word 2002 and any pointers in the right direction will be
most appreciated.



--
Regards,
David




Word VBA >> select text and assign to variable

by Doug Robbins » Sun, 08 Aug 2004 07:38:38 GMT


Hi David,

Dim sItem1 As String, sItem2 As String, sItem3 As String, sItem4 As String,
Item As String
With ActiveDocument
sItem1 = .Paragraphs(1).Range.Text
sItem2 = .Paragraphs(2).Range.Text
sItem3 = .Paragraphs(3).Range.Text
sItem4 = .Paragraphs(4).Range.Text
End With

See the article "Getting To Grips With VBA Basics In 15 Minutes" at:

http://word.mvps.org/FAQs/MacrosVBA/VBABasicsIn15Mins.htm

and other information on that site.
--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP







Word VBA >> select text and assign to variable

by fitful_thought » Sun, 08 Aug 2004 08:59:36 GMT

Doug,

Thank you for your help.

David



String,
paid


will




Similar Threads

1. Assign a radio button's tag property to a text variable txBtn

Below is some code from a form that I'm making.
I inserted my question in the bracketted text 
(essentially, I want this line to assign the button's tag 
property value (e.g., the letter "L") to a text variable 
txBtn).
Any help would be appreciated.
fyi, I'm defining the text variable txBtn in the 
subroutine that calls the form, as follows:  dim txBtn as 
text.  Another subroutine (InsertRorCInTable) will use 
the value assigned to txBtn, in determining whether to 
insert a row above or below, or a column to the right or 
to the left.
Here's the code.....

Private Sub radInsertColLt_Click()
     [I want this line to assign the button's tag 
property value (i.e., the letter "L") to a text variable 
txBtn, but I can't figure out how to do it]
    Call InsertRorCInTable
End Sub
Private Sub radInsertColLt_DblClick(ByVal Cancel As 
MSForms.ReturnBoolean)
     [I want this line to assign the button's tag 
property value (i.e., the letter "L") to a text variable 
txBtn, but I can't figure out how to do it]
    Call InsertRorCInTable
End Sub

2. Assign text and variables into an array - MS Word&VBA

3. Assign a radio button's tag property to a text variable txBtn

Below is some code from a form that I'm making.
I inserted my question in the bracketted text 
(essentially, I want this line to assign the button's tag 
property value (e.g., the letter "L") to a text variable 
txBtn).
Any help would be appreciated.
fyi, I'm defining the text variable txBtn in the 
subroutine that calls the form, as follows:  dim txBtn as 
text.  Another subroutine (InsertRorCInTable) will use 
the value assigned to txBtn, in determining whether to 
insert a row above or below, or a column to the right or 
to the left.
Here's the code.....

Private Sub radInsertColLt_Click()
     [I want this line to assign the button's tag 
property value (i.e., the letter "L") to a text variable 
txBtn, but I can't figure out how to do it]
    Call InsertRorCInTable
End Sub
Private Sub radInsertColLt_DblClick(ByVal Cancel As 
MSForms.ReturnBoolean)
     [I want this line to assign the button's tag 
property value (i.e., the letter "L") to a text variable 
txBtn, but I can't figure out how to do it]
    Call InsertRorCInTable
End Sub

4. Assigning text to variable - Word VBA

5. Assign a radio button's tag property to a text variable txBtn

Below is some code from a form that I'm making.
I inserted my question in the bracketted text 
(essentially, I want this line to assign the button's tag 
property value (e.g., the letter "L") to a text variable 
txBtn).
Any help would be appreciated.
fyi, I'm defining the text variable txBtn in the 
subroutine that calls the form, as follows:  dim txBtn as 
text.  Another subroutine (InsertRorCInTable) will use 
the value assigned to txBtn, in determining whether to 
insert a row above or below, or a column to the right or 
to the left.
Here's the code.....

Private Sub radInsertColLt_Click()
     [I want this line to assign the button's tag 
property value (i.e., the letter "L") to a text variable 
txBtn, but I can't figure out how to do it]
    Call InsertRorCInTable
End Sub
Private Sub radInsertColLt_DblClick(ByVal Cancel As 
MSForms.ReturnBoolean)
     [I want this line to assign the button's tag 
property value (i.e., the letter "L") to a text variable 
txBtn, but I can't figure out how to do it]
    Call InsertRorCInTable
End Sub

6. Assign text from a Word document to a variable - Microsoft Office Access

7. Assigning selected text to autocorrect, changing case

I learned that it is possible to write a macro to assign selected text to an 
autocorrect entry from another thread in this forum. So if autocorrect entry 
is "uu", then the code would be:
AutoCorrect.Entries.Add Name:="uu", Value:=Selection.Text

But suppose the selected text is in upper case and one wants it to be 
assigned to "UU" in title case. How would one do that?

8. Assigning a Variable to an Expression that Includes a Variable and VBA Property - Excel