The first character position in a document is always zero and the last is equivalent to the number of characters in the document.

The Range object also selects paragraphs. The following example selects the third paragraph in the active document and pastes it in Excel. Depending on how the paste is done, the text can be pasted into a text box (see Figure 16.5) or into a cell (see Figure 16.6):

Sub SelectSentence()

Dim wdApp As Word.Application

Dim wdRng As Word.Range

Set wdApp = GetObject(, "Word.Application")

With wdApp.ActiveDocument

If .Paragraphs.Count >= 3 Then

Set wdRng = .Paragraphs(3).Range wdRng.Copy End If End With

'This line pastes the copied text into a text box Worksheets("Sheet2").PasteSpecial

'These two lines paste the copied text in cell A1

'Note that the range must be selected and then we can paste the text



Set wdApp = Nothing Set wdRng = Nothing End Sub

Figure 16.5

Paste Word text into an Excel text box.

0 0

Post a comment