Getting word toolbar to reflect context of cursor position 
Author Message
 Getting word toolbar to reflect context of cursor position

Hello,

I cannot find a way to do this and doubt that it can be
done but I thought I'd see if anyone knows of way.

I have a word toolbar with some dropdowns.  When the user
has their cursor in an area of text that corresponds to
something that you can choose in a dropdown I want to have
that dropdown automatically detect that the cursor is in
an area of one of its items and then select that item
(change the .ListIndex to be the appropriate one)?

thanks,

Chris



Sun, 31 Jul 2005 06:22:18 GMT  
 Getting word toolbar to reflect context of cursor position
Hi Chris,

Quote:
> (change the .ListIndex to be the appropriate one)?

There you go, affirmative.

    'this defaults the commandbar combo to the
    'Selection.Range text in your document.
    cbo.ListIndex = GetListIndex(Selection.Range.Text, cbo)

The function to go with it (just as an example):

Function GetListIndex(SelectionText As String, _
    MyCombo As CommandBarComboBox) As Long

    For x = 1 To MyCombo.ListCount
        If SelectionText = MyCombo.List(x) Then
            GetListIndex = x
            Exit Function
        End If
    Next
End Function

Krgrds,
Perry



Quote:
> Hello,

> I cannot find a way to do this and doubt that it can be
> done but I thought I'd see if anyone knows of way.

> I have a word toolbar with some dropdowns.  When the user
> has their cursor in an area of text that corresponds to
> something that you can choose in a dropdown I want to have
> that dropdown automatically detect that the cursor is in
> an area of one of its items and then select that item
> (change the .ListIndex to be the appropriate one)?

> thanks,

> Chris



Tue, 02 Aug 2005 06:43:26 GMT  
 Getting word toolbar to reflect context of cursor position
Hi Chris,

Quote:
> Can you think of a way to get an event like cursor position to invoke a

function?
The only way this be done is by raising the eventhandler up the application
level.
Look it up in the online VBA help, topic: Application Object
or look in
http://www.mvps.org/word/FAQs/MacrosVBA/AppClassEvents.htm

If you can't manage to raise the eventhandler up to this level, repost but
start up
a new thread/

Under the newly created class module, following event will suit yr purpose:
WindowSelectionChange

Note: because the scope of this eventhandler goes beyond the scope of
yr target template/addin/document, you'll have to utilize a strict
error handling and a correct document assignment in code,
like examplified below.

Private Sub App_WindowSelectionChange(ByVal Sel As Selection)
    On Error GoTo DoNothing
    'are we speaking abt the correct document being active?
    If ActiveDocument = Documents("TheRight.Doc") Then
        Dim cbo As Object
        'document is loaded, so is the commandbar
        Set cbo = CommandBars("MyBar").Controls("MyCombo")
        On Error Resume Next
        'note: line continuation mark in following code line
        cbo.ListIndex = _
            GetListIndex(Selection.Range.Text, cbo)
        Set cbo = Nothing
    End If
ExitHere:
    Exit Sub
Foutje:
    Resume ExitHere
End Sub

Krgrds,
Perry



Quote:
> Hi Chris,

> > (change the .ListIndex to be the appropriate one)?
> There you go, affirmative.

>     'this defaults the commandbar combo to the
>     'Selection.Range text in your document.
>     cbo.ListIndex = GetListIndex(Selection.Range.Text, cbo)

> The function to go with it (just as an example):

> Function GetListIndex(SelectionText As String, _
>     MyCombo As CommandBarComboBox) As Long

>     For x = 1 To MyCombo.ListCount
>         If SelectionText = MyCombo.List(x) Then
>             GetListIndex = x
>             Exit Function
>         End If
>     Next
> End Function

> Krgrds,
> Perry



> > Hello,

> > I cannot find a way to do this and doubt that it can be
> > done but I thought I'd see if anyone knows of way.

> > I have a word toolbar with some dropdowns.  When the user
> > has their cursor in an area of text that corresponds to
> > something that you can choose in a dropdown I want to have
> > that dropdown automatically detect that the cursor is in
> > an area of one of its items and then select that item
> > (change the .ListIndex to be the appropriate one)?

> > thanks,

> > Chris



Wed, 03 Aug 2005 05:11:48 GMT  
 Getting word toolbar to reflect context of cursor position
Hi Chris,

Quote:
> Can you think of a way to get an event like cursor position to invoke a

function?
The only way this be done is by raising the eventhandler up the application
level.
Look it up in the online VBA help, topic: Application Object
or look in
http://www.mvps.org/word/FAQs/MacrosVBA/AppClassEvents.htm

If you can't manage to raise the eventhandler up to this level, repost but
start up
a new thread/

Under the newly created class module, following event will suit yr purpose:
WindowSelectionChange

Note: because the scope of this eventhandler goes beyond the scope of
yr target template/addin/document, you'll have to utilize a strict
error handling and a correct document assignment in code,
like examplified below.

Private Sub App_WindowSelectionChange(ByVal Sel As Selection)
    On Error GoTo DoNothing
    'are we speaking abt the correct document being active?
    If ActiveDocument = Documents("TheRight.Doc") Then
        Dim cbo As Object
        'document is loaded, so is the commandbar
        Set cbo = CommandBars("MyBar").Controls("MyCombo")
        On Error Resume Next
        'note: line continuation mark in following code line
        cbo.ListIndex = _
            GetListIndex(Selection.Range.Text, cbo)
        Set cbo = Nothing
    End If
ExitHere:
    Exit Sub
Foutje:
    Resume ExitHere
End Sub

Krgrds,
Perry



Quote:
> Hi Chris,

> > (change the .ListIndex to be the appropriate one)?
> There you go, affirmative.

>     'this defaults the commandbar combo to the
>     'Selection.Range text in your document.
>     cbo.ListIndex = GetListIndex(Selection.Range.Text, cbo)

> The function to go with it (just as an example):

> Function GetListIndex(SelectionText As String, _
>     MyCombo As CommandBarComboBox) As Long

>     For x = 1 To MyCombo.ListCount
>         If SelectionText = MyCombo.List(x) Then
>             GetListIndex = x
>             Exit Function
>         End If
>     Next
> End Function

> Krgrds,
> Perry



> > Hello,

> > I cannot find a way to do this and doubt that it can be
> > done but I thought I'd see if anyone knows of way.

> > I have a word toolbar with some dropdowns.  When the user
> > has their cursor in an area of text that corresponds to
> > something that you can choose in a dropdown I want to have
> > that dropdown automatically detect that the cursor is in
> > an area of one of its items and then select that item
> > (change the .ListIndex to be the appropriate one)?

> > thanks,

> > Chris



Wed, 03 Aug 2005 05:11:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Getting Cursor position

2. Getting Cursor position in text box - how?

3. Find current cursor position in Word problem

4. Cursor position in Word

5. cursor position in word

6. Cursor Position in Word

7. Finding Font and Attributes Used at Cursor Position (Like MS-Word)

8. cant find cursor position in a word app

9. Word text cursor position

10. Graphics positioning with device context in VB

11. Graphics positioning with device context in VB

12. Custom Menu/Toolbars & Customization Context

 

 
Powered by phpBB® Forum Software