Range object, Selection object 
Author Message
 Range object, Selection object

I do not know whether I should use a Range obj or
Selection obj. I suspect I need a Range but I don't know
how to set the Range object (oRange) initially.

I need to format some text as TitleCase (wdTitleWord). The
text I am doing this to is a string:
  Word.ActiveDocument.Range.InsertAfter strString
where strString is my "unformatted" (ie, ALLCAPS instead
of TitleCase) string.

The thing is, I need the text to be title case. Only my
string needs to be title case, not the rest of the
document. So I thought maybe I needed to use a Range
object in order to accomplish this.
  set oRange = (this is what I don't know)
  oRange.Text = strString
  oRange.Case = wdTitleWord
  Word.ActiveDocument.Range.InsertAfter oRange
But as you can see, my object variable (oRange) is not
set. How do I set oRange = something so that I can use its
text and case properties and then paste in my TitleCase
text. Any advice appreciated.



Wed, 01 Dec 2004 00:17:27 GMT  
 Range object, Selection object
Hi muldoon,

I think the following will take care of what you're trying to accomplish:

Dim s As String
Dim r As Range
s = "ALLCAPS SENTENCE"
Set r = ActiveDocument.Range
r.Collapse wdCollapseEnd
r.InsertAfter s
r.Case = wdTitleWord

HTH

Quote:
> I do not know whether I should use a Range obj or
> Selection obj. I suspect I need a Range but I don't know
> how to set the Range object (oRange) initially.

> I need to format some text as TitleCase (wdTitleWord). The
> text I am doing this to is a string:
>   Word.ActiveDocument.Range.InsertAfter strString
> where strString is my "unformatted" (ie, ALLCAPS instead
> of TitleCase) string.

> The thing is, I need the text to be title case. Only my
> string needs to be title case, not the rest of the
> document. So I thought maybe I needed to use a Range
> object in order to accomplish this.
>   set oRange = (this is what I don't know)
>   oRange.Text = strString
>   oRange.Case = wdTitleWord
>   Word.ActiveDocument.Range.InsertAfter oRange
> But as you can see, my object variable (oRange) is not
> set. How do I set oRange = something so that I can use its
> text and case properties and then paste in my TitleCase
> text. Any advice appreciated.



Wed, 01 Dec 2004 01:19:25 GMT  
 Range object, Selection object
danke Mr. Lett.

Quote:
>-----Original Message-----
>Hi muldoon,

>I think the following will take care of what you're

trying to accomplish:
Quote:

>Dim s As String
>Dim r As Range
>s = "ALLCAPS SENTENCE"
>Set r = ActiveDocument.Range
>r.Collapse wdCollapseEnd
>r.InsertAfter s
>r.Case = wdTitleWord

>HTH




Quote:
>> I do not know whether I should use a Range obj or
>> Selection obj. I suspect I need a Range but I don't know
>> how to set the Range object (oRange) initially.

>> I need to format some text as TitleCase (wdTitleWord).
The
>> text I am doing this to is a string:
>>   Word.ActiveDocument.Range.InsertAfter strString
>> where strString is my "unformatted" (ie, ALLCAPS instead
>> of TitleCase) string.

>> The thing is, I need the text to be title case. Only my
>> string needs to be title case, not the rest of the
>> document. So I thought maybe I needed to use a Range
>> object in order to accomplish this.
>>   set oRange = (this is what I don't know)
>>   oRange.Text = strString
>>   oRange.Case = wdTitleWord
>>   Word.ActiveDocument.Range.InsertAfter oRange
>> But as you can see, my object variable (oRange) is not
>> set. How do I set oRange = something so that I can use
its
>> text and case properties and then paste in my TitleCase
>> text. Any advice appreciated.

>.



Wed, 01 Dec 2004 02:23:01 GMT  
 Range object, Selection object
I spoke too soon. I commented out my code and copied your
code directly into my VBEditor... it worked fine. I then
removed the comments from my code and changed it to the
following. It would seem this would be incorporating your
suggestion while retaining how my code gets the ALLCAPS
value in question. However an "invalid property" error
appears on r.Case wdTitleWord. i've looked at it a couple
times and I dont know if I am overlooking an obvious
problem or what. What do you think of the following
(variable names changed to protect the guilty)...

Dim strReturnValue As String
Dim objMyObject As DLLName.clsClass
Dim oRange As Range
On Error GoTo LocalErrorHandler

   'Request the list:
   Set objMyObject = New DLLName.clsClass
      strReturnValue = objMyObject.GetReturnValues
   Set objMyObject = Nothing

   'Paste into current doc:
   If Trim(strReturnValue) <> "" Then
      Set oRange = ActiveDocument.Range
      oRange.Collapse wdCollapseEnd
      oRange.InsertAfter strReturnValue
      oRange.Case wdTitleWord
   End If

Quote:
>-----Original Message-----
>Hi muldoon,

>I think the following will take care of what you're

trying to accomplish:
Quote:

>Dim s As String
>Dim r As Range
>s = "ALLCAPS SENTENCE"
>Set r = ActiveDocument.Range
>r.Collapse wdCollapseEnd
>r.InsertAfter s
>r.Case = wdTitleWord

>HTH




Quote:
>> I do not know whether I should use a Range obj or
>> Selection obj. I suspect I need a Range but I don't know
>> how to set the Range object (oRange) initially.

>> I need to format some text as TitleCase (wdTitleWord).
The
>> text I am doing this to is a string:
>>   Word.ActiveDocument.Range.InsertAfter strString
>> where strString is my "unformatted" (ie, ALLCAPS instead
>> of TitleCase) string.

>> The thing is, I need the text to be title case. Only my
>> string needs to be title case, not the rest of the
>> document. So I thought maybe I needed to use a Range
>> object in order to accomplish this.
>>   set oRange = (this is what I don't know)
>>   oRange.Text = strString
>>   oRange.Case = wdTitleWord
>>   Word.ActiveDocument.Range.InsertAfter oRange
>> But as you can see, my object variable (oRange) is not
>> set. How do I set oRange = something so that I can use
its
>> text and case properties and then paste in my TitleCase
>> text. Any advice appreciated.

>.



Wed, 01 Dec 2004 02:44:15 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Using Range object instead of Selection

2. Working with Range / Selection Objects

3. Word 97/XP Range vs Selection Object

4. Converting a Selection/Range Object to HTML

5. Word Object Model : Find a position within a Range or Selection

6. Using the Range object in Excel Object Library 9.0

7. VBA EXCEL97: How to get the range from a chart into a range object

8. Crystal Reports 8.5 date range parameter field - record selection that includes null date range

9. Pasting Excel range as embedded object in outlooks body

10. Range Object

11. HTML of Range object

12. How to initialize Range object with Current page

 

 
Powered by phpBB® Forum Software