Posibles bases de solución en Application.WindowSelectionChange Event
. Por lo tanto, debe mantener los siguientes pasos:
1.cree el módulo de clase
2. Nombra tu módulo de clase App
3. Agregue el siguiente código a App Class Module
:
Public WithEvents WRD As Application
Private Sub WRD_WindowSelectionChange(ByVal Sel As Selection)
'here you should place solution from your Document_Open sub
'which defines color based on user name or...
'you could place it somewhere else but pass color value
'here as a parameter
'for test I just assumed that color should be blue
Sel.Font.Color = wdColorBlue
End Sub
4.En Módulo estándar Agregar variable pública:
Public tmpApp As New App
5. Crear sub en el módulo estándar, o agregar código a su Document_Open Event
, que inicializará nuestra clase:
Sub Document_Open_new()
Set tmpApp.WRD = Application
'we need to change selection once to trigger full
'scope of solution
'if we omit the code below new color will not work
'if user add new text at the beginning of the document
'right after it was opened
Dim tmpSel As Range
Set tmpSel = Selection.Range
ActiveDocument.Bookmarks("\EndOfDoc").Select
tmpSel.Select
End Sub
6. Run el submarino anterior una vez o el documento abierto si el código se agregó a Document_open event
.
---EDITAR--- (Después de algunos comentarios de @sid a continuación)
Hay algunos inconvenientes del uso de la solución propuesta. Sin embargo, la mayoría de ellos podrían resolverse agregando algunos If statements
en el interior WindowSelectionChange event
. Comprobando la posición de Sel range
El parámetro, el texto alrededor y otros permiten decidir con precisión si se debe aplicar el nuevo color o no.