get the text from a selection.range (a bug)

T

thalos

Hello

Is Somebody be able to solve my bug ?

Sub occurence()

Dim lStart As Long
Dim objWdRange As Range
Dim objWd1 As Range
Dim Num1 As Integer
Selection.GoTo wdGoToLine, wdGoToLast

NumLines
ActiveDocument.BuiltInDocumentProperties(wdPropertyLines)
Selection.GoTo wdGoToLine, wdGoToFirst
Selection.Expand wdLine
Set objWd1 Selection.Range.Text 'error incompatibility of type
'I want to get the text from a certain selection.range
'what have I to do ?
'that's why I must use: selection.range.text
Selection.Collapse wdCollapseEnd

End Su
 
P

Peter Hewett

Hi Thalos

I'm not sure what your codes doing or supposed to be doing, you don't say.
I've also assumed you've just posted part of the code as there are many
variables defined but not used and one used but not defined.

Assuming you want the first line of text in a document you can use:

Sub occurence()
Dim rngLine As Word.Range

' Setup range object
Set rngLine = ActiveDocument.Content
rngLine.Collapse wdCollapseStart

' Transfet to the selection object as a range object
' does not support Expand wdLine
rngLine.Select
Selection.Expand wdLine
MsgBox "The first line is: " & vbCr & Selection.Text
End Sub

or even:

Sub occurence()
Selection.HomeKey Unit:=wdStory
Selection.Expand wdLine
MsgBox "The first line is: " & vbCr & Selection.Text
End Sub

The first example gives you a range object you might want to maniputlate.

HTH + Cheers - Peter
 

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