How to navigate next and previous comments by word macro

User avatar
Sam1085
3StarLounger
Posts: 318
Joined: 23 Aug 2016, 07:43
Location: Sri Lanka

How to navigate next and previous comments by word macro

Post by Sam1085 »

Hi,

I'm trying to insert 02 buttons into my custom ribbon toolbar.
01. Next Comment
02. Previous Comment

I know it's already appear on 'Review' tab in MS Word. But I don't know the exact callback ID for that.

Is there any URL to refer all of the MS Word ribbon callback functions?

Thanks!
-Sampath-

User avatar
HansV
Administrator
Posts: 78883
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to navigate next and previous comments by word macro

Post by HansV »

Does idMso tables help?
Best wishes,
Hans

User avatar
Sam1085
3StarLounger
Posts: 318
Joined: 23 Aug 2016, 07:43
Location: Sri Lanka

Re: How to navigate next and previous comments by word macro

Post by Sam1085 »

Thank you Hans,

I found 02 Control IDs for this. Now I've to insert those IDs into my ribbon xml file. I added it as follows. But not works for me.

Code: Select all

<button 
id="B9"
image="n"
label="Next"
screentip="Next"
showImage="true"
showLabel="true"
size="normal"
supertip="Go To Next Comment"
visible="true"
onAction="ReviewNextComment"/>

<button 
id="B10"
image="p"
label="Previous"
screentip="Previous"
showImage="true"
showLabel="true"
size="normal"
supertip="Go To Previous Comment"
visible="true"
onAction="ReviewPreviousComment"/>
I think it cannot be use as 'onAction'.
-Sampath-

User avatar
HansV
Administrator
Posts: 78883
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to navigate next and previous comments by word macro

Post by HansV »

Try using ReviewNextCommentWord instead of ReviewNextComment, and ReviewPreviousCommentWord instead of ReviewPreviousComment
Best wishes,
Hans

User avatar
Sam1085
3StarLounger
Posts: 318
Joined: 23 Aug 2016, 07:43
Location: Sri Lanka

Re: How to navigate next and previous comments by word macro

Post by Sam1085 »

Hi Hans,

I tried ReviewNextCommentWord and ReviewPreviousCommentWord. But I think still It's not call to the exact word command. I got the following warning message:
img1.png
You do not have the required permissions to view the files attached to this post.
-Sampath-

User avatar
HansV
Administrator
Posts: 78883
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to navigate next and previous comments by word macro

Post by HansV »

I'm afraid I can't help you, sorry.
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8254
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: How to navigate next and previous comments by word macro

Post by stuck »

To call a macro from a Ribbon button created by RibbonX XML you must indicate that the macro is a 'Ribbon thingy' (my terminolgy :grin). What I mean is, you can't call a macro via 'onAction=' in XML unless your macro is named in the following style:

Code: Select all

Sub MyMacro(control As IRibbonControl)
     code goes here
End Sub
However, once you've defined your Sub in that way you can't then just run it from the VBE without first removing the (control As IRibbonControl) bit and that makes debugging fiddly as you're constantly editing the name of the macro. To ease this, I've organised things as follows:
1) Inserted a module called modRibbonCalls
2) In that module, created as many Subs as I have macros on my Ribbon tab. Each Sub is named in the style:
    Sub rbnMyMacro1(control As IRibbonControl)
3) Each Sub contains only one line, a call to the relevant macro
    Call MyMacro1
4) In the XML, point each 'onAction' to the relevant 'rbn' version of the macro
    onAction=rbnMyMacro1

Does this help?

Ken

User avatar
Sam1085
3StarLounger
Posts: 318
Joined: 23 Aug 2016, 07:43
Location: Sri Lanka

Re: How to navigate next and previous comments by word macro

Post by Sam1085 »

Thank you Hans and Stuck,

Earlier I used 02 simple macros to jump a comment by comment. It's works perfectly.

Code: Select all

'Next Comment
Private Sub NextComment(control As IRibbonControl)
    Selection.GoToNext wdGoToComment
End Sub

'Previous Comment
Private Sub PreviousComment(control As IRibbonControl)
    Selection.GoToPrevious wdGoToComment
End Sub
My only concern is the above macros not selecting the current comment placement (Please see below image for more clarity). Any way to develop this macro to jump comment by comment and select current comment place by a macro? (Similar option already available on Reviews >> Next/Previous buttons. But I've no idea to add those buttons to my custom ribbon toolbar)
img2.png
Thanks and have a great week end!
You do not have the required permissions to view the files attached to this post.
-Sampath-

User avatar
HansV
Administrator
Posts: 78883
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to navigate next and previous comments by word macro

Post by HansV »

The built-in buttons and the macros that you posted operate in exactly the same way as far as I can tell. But the way they work depends on where the selection/insertion point is located:

If the selection/insertion point is located in the body of the document, the anchor of the next (or previous) comment will be selected.
If the selection/insertion point is located in the text of a comment, you'll be taken to the next (or previous) comment.
Best wishes,
Hans

User avatar
Sam1085
3StarLounger
Posts: 318
Joined: 23 Aug 2016, 07:43
Location: Sri Lanka

Re: How to navigate next and previous comments by word macro

Post by Sam1085 »

Hi Hans,

Thank you for your quick response.

Yah.. I got your point. So, is there any way to change cursor location point in above macro to select comment?
-Sampath-

User avatar
HansV
Administrator
Posts: 78883
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to navigate next and previous comments by word macro

Post by HansV »

As far as I can tell, that is not possible, but perhaps someone else knows how to do that.
Best wishes,
Hans

User avatar
Sam1085
3StarLounger
Posts: 318
Joined: 23 Aug 2016, 07:43
Location: Sri Lanka

Re: How to navigate next and previous comments by word macro

Post by Sam1085 »

Thank you Hans. I'll try to find some solution for that. :thankyou:
-Sampath-