Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multiple text formats in a single MS Word header object
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00545354
Message ID:
00546970
Views:
15
>Hi Jay:
>
>Using the Word macro recorder I see it defines an text area as a selection when you want to apply different attributes to various portions of text within a header. I think what have to do is translate the selections into a ranges.
>
>Charlie

Charlie --

The Word Basic documentation has the following example (which, of course, needs to be converted to VFP) of assigning text characteristics to selected text. The first example uses the selection object, the 2nd -- similar to the example you showed -- uses only the range object.
Remarks

Use the Range property to return a Range object from the Selection object. The following example defines the variable myRange as the selected range.

Set myRange = Selection.Range
When you record macros, the macro recorder will often record changes to the Selection object. The following recorded macro applies bold formatting to the first two words in the document, and then inserts a new paragraph.

Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=2, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
The following example accomplishes the same task as the preceding example, but without using the Selection object.

Set myRange = ActiveDocument.Range(Start:=0, _
    End:=ActiveDocument.Words(2).End)
myRange.Bold = True
myRange.InsertParagraphAfter
I think that you have to use the Selection object to select your beginning and ending points.

If you prefer to use the range object, you can access the Start and End properties and create the begining and ending of a range. Again from the docs which sets the start and end position to the same value and applies it to define a range begin and end:
pos = Selection.End
Set myRange = ActiveDocument.Range(Start:=pos, End:=pos)
ActiveDocument.Fields.Add Range:=myRange, Type:=wdFieldAuthor
P.S. Just a quibble, but I always thought that the pairs were: being and end, start and finish ... Oh well, the brave new world of English brought to us by MS!

HTH,

Jay
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform