select text and assign to variable

F

fitful_thought

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.
 
D

Doug Robbins

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
 
F

fitful_thought

Doug,

Thank you for your help.

David

Doug Robbins said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top