Results 1 to 11 of 11
  1. #1
    New Lounger
    Join Date
    Jan 2003
    Location
    Atlanta
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Holding Selection (XP)

    I need to select some text and then perform two operations without selecting again. More specifically, I need to highlight it in yellow and then copy it somewhere so that it is yellow in both places. Now, I must select it twice.

    Thanks

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Holding Selection (XP)

    If you use Ranges instead of Selections, then you can do multiple things on it without having to reselect.

    Here is a snippet that will highlight the selection Yellow, Italicise it and then paste it at the end of the document.

    Dim rng As Range
    'Set the range to the current selection
    Set rng = Selection.Range
    'Highlight Yellow
    rng.HighlightColorIndex = wdYellow
    'Italicise
    rng.Font.Italic = True
    'Copy
    rng.Copy
    'Move to the end of the document
    Selection.Move wdStory
    'Paste the newly formatted range
    Selection.Paste
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Holding Selection (XP)

    If you mean "interactively," rather than in a program, I think you are somewhat out of luck. Why does Word collapse the selection after highlighting, when it doesn't do this for any of the other common formatting commands? My guess is that this is so you can see the color, rather than the reverse of the color (which is what you see if you reselect the highlighted area).

    So, turning to the option of using VBA code, Bryan has supplied a solution. You can save this in your Normal.dot template and create a button for it on one of your toolbars. It would be neat to try to change the built-in behavior of the highlighter drop-down control, but this would take me hours to figure out (at least), so that will have to wait for another day. (Such as a Saturday. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> )

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Holding Selection (XP)

    My guess is that Word does this because highlighting isn't a font characteristic (unlike bold or italic formatting).

    Depending on what you're trying to do, however, you may be able to use shading rather than highlighting - via the Tables and Borders toolbar.

  5. #5
    Lounger
    Join Date
    Oct 2004
    Location
    Indianapolis, Indiana, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Holding Selection (XP)

    Any chance that TweakUI can change this setting?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Holding Selection (XP)

    TweakUI is intended to edit Windows settings, it doesn't let you change Word settings.

  7. #7
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Holding Selection (XP)

    > It would be neat to change the built-in behaviour [...]

    Isn't too hard:<pre>
    Sub Highlight()
    Dim myRng As Range
    Set myRng = Selection.Range.Duplicate
    WordBasic.Highlight
    Selection.Start = myRng.Start
    End Sub
    </pre>

    (the trick being to call the macro "Highlight" so it runs instead of the built-in command)

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Holding Selection (XP)

    Klaus, I haven't tried this, but I find it very odd that you can use WordBasic.Highlight for a feature that was introduced in the age of VBA! It makes me wonder what other methods might have snuck into the WordBasic object while I wasn't paying attention.

  9. #9
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Holding Selection (XP)

    I just tried with a new dialog and the info from the VBA help page (wdDialogFitText FitTextWidth):

    WordBasic.FormatFitText FitTextWidth:=60

    Select a few words and run that ... and it does work.

    Of course there's probably no good reason why you would use that instead of proper VBA code
    Selection.Range.FitTextWidth = MillimetersToPoints(60)

    But if you're desperate because VBA doesn't do something the way you want, maybe it might help in rare cases to try old WordBasic...

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  10. #10
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Holding Selection (XP)

    All of 'em <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    The built-in commands, old and new, can all be called through the WordBasic object. At least it works for all the button controls that you can add to the interface.
    So if you intercept some built-in command, you can always put in the default behaviour.

    For the WordBasic functions that take arguments, you can usually find new arguments that have been added in recent versions by trial and error, or look up in the Object browser whether the wdConstants correspond to the arguments in the old WordBasic functions.

    added later: Or you can look up the VBA help topic on arguments for the built-in dialogs ... only, the variable type and allowed values aren't given, so it would still be guesswork to figure it out.

    Howard Kaikow has posted that you can get them from the object library, too post 157,670.
    Unfortunately, I didn't ask him where you can get at this listing... Do you know?
    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Holding Selection (XP)

    It's strange but potentially useful. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Regarding the declarations, I wonder whether an API viewer extracted that from the type/object library?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •