가능한 해결 방법 Application.WindowSelectionChange Event
. 따라서 다음 단계를 유지해야합니다.
1. 클래스 모듈을 생성합니다
2. 클래스 모듈의 이름 App
3. 다음 코드를 제공하십시오 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. 표준 모듈에서 공개 변수 추가 :
Public tmpApp As New App
5. 표준 모듈에서 하위를 만들거나 코드를 추가하십시오. Document_Open Event
, 수업을 초기화 할 것입니다.
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. 코드가 추가 된 경우 위의 서브를 한 번 또는 열기 문서를 열었습니다. Document_open event
.
---편집하다--- (아래 @SID의 일부 의견 후)
제안 된 솔루션을 사용하는 데는 불편 함이 있습니다. 그러나 대부분은 일부를 추가하여 해결할 수 있습니다. If statements
내부에 WindowSelectionChange event
. 위치 확인 Sel range
매개 변수, 텍스트 주변 및 기타를 사용하면 새로운 색상이 적용되어야하는지 여부를 정확하게 결정할 수 있습니다.