[FONT=Monaco, Menlo, Consolas, Roboto Mono, Andale Mono, Ubuntu Mono, monospace]Hi,
My goal is to trigger a macro when a comment is added to a cell (otherwise, the cell is not modified) from the column B.
I was given this script to place at the root of the sheet, which applies to a given cell (B2) instead of the column B.
This piece code is functionnal with Excel 2013 but inactive with the latest Office 365 version.
It seems that the comments’ integration was changed since Excel 2016. Cosmetically, it is now different, but programatically, it seems also...
Any idea how to fix / adapt this code to make it work ? Thanks a lot (my skill level is between noob and intermediary—)
[/FONT]
My goal is to trigger a macro when a comment is added to a cell (otherwise, the cell is not modified) from the column B.
I was given this script to place at the root of the sheet, which applies to a given cell (B2) instead of the column B.
Code:
[/COLOR][/FONT][COLOR=#770088][FONT=inherit]Private[/FONT][/COLOR][COLOR=#141414][FONT=inherit] [/FONT][/COLOR][COLOR=#770088][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#141414][FONT=inherit] Worksheet_SelectionChange[/FONT][/COLOR][COLOR=#141414][FONT=inherit]([/FONT][/COLOR][COLOR=#770088][FONT=inherit]ByVal[/FONT][/COLOR][COLOR=#141414][FONT=inherit] Target [/FONT][/COLOR][COLOR=#770088][FONT=inherit]As[/FONT][/COLOR][COLOR=#141414][FONT=inherit] Range[/FONT][/COLOR][COLOR=#141414][FONT=inherit])[/FONT][/COLOR]
<code class=" language-vb" style="box-sizing: border-box; font-family: inherit; font-size: 1em;">[COLOR=#770088]If[/COLOR] Target.Address = [COLOR=#AA1111]"$B$2"[/COLOR] [COLOR=#770088]Then[/COLOR]
[COLOR=#770088]If[/COLOR] HasComment(Target) [COLOR=#770088]Then[/COLOR] [D2] = [COLOR=#AA1111]"test réussi"[/COLOR]
[COLOR=#770088]End[/COLOR] [COLOR=#770088]If[/COLOR]
[COLOR=#770088]End[/COLOR] [COLOR=#770088]Sub[/COLOR]
[COLOR=#770088]Private[/COLOR] [COLOR=#770088]Function[/COLOR] HasComment(Cell [COLOR=#770088]As[/COLOR] Range) [COLOR=#770088]As[/COLOR] [COLOR=#770088]Boolean[/COLOR]
[COLOR=#770088]Dim[/COLOR] oComment [COLOR=#770088]As[/COLOR] Comment
[COLOR=#770088]On[/COLOR] [COLOR=#770088]Error[/COLOR] [COLOR=#770088]Resume[/COLOR] [COLOR=#770088]Next[/COLOR]
[COLOR=#770088]Set[/COLOR] oComment = Cell.Comment
[COLOR=#770088]If[/COLOR] [COLOR=#770088]Not[/COLOR] (oComment [COLOR=#770088]Is[/COLOR] [COLOR=#221199]Nothing[/COLOR]) [COLOR=#770088]Then[/COLOR] HasComment = [COLOR=#221199]True[/COLOR]
</code>[COLOR=#770088][FONT=inherit]End[/FONT][/COLOR][COLOR=#141414][FONT=inherit] [/FONT][/COLOR][COLOR=#770088][FONT=inherit]Function[/FONT][/COLOR][FONT=Monaco, Menlo, Consolas, Roboto Mono, Andale Mono, Ubuntu Mono, monospace][COLOR=#141414]
This piece code is functionnal with Excel 2013 but inactive with the latest Office 365 version.
It seems that the comments’ integration was changed since Excel 2016. Cosmetically, it is now different, but programatically, it seems also...
Any idea how to fix / adapt this code to make it work ? Thanks a lot (my skill level is between noob and intermediary—)
[/FONT]