문제

그래서 저는 3 개가있는 각 그룹에 문서에 입력을 위해 글꼴 색상이 할당 된 일부 사람들을위한 문서를 만들기 위해 노력하고 있습니다. 나는 관련된 모든 사람의 목록이 포함 된 VBA 스크립트를 작성했으며 컴퓨터에 로그인 한 사람과 그 그룹을 식별 할 수 있습니다. 그러나 글꼴 색상을 설정할 수 없습니다. 단어가 어떻게 작동 하는지를보기 위해 글꼴 색상을 설정하는 VBA 스크립트를 녹음했지만 결과 코드 Selection.Font.Color = wdColorRed VBA 스크립트에 추가하면 선택한 글꼴 색상이 실제로 변경되지 않습니다. 다음은 내가 사용하는 코드의 예입니다.

Private Sub Document_Open()

Dim Users As New Scripting.Dictionary
Dim UserID As String
Dim category As String

UserID = GetUserName 'Currently using the example at
                     'http://support.microsoft.com/kb/161394 as a function

'---Add Members of Group 1---
Users.Add "person1", "group1"
Users.Add "person2", "group1"

'---Add Members of Group 2---
Users.Add "person3", "group2"
Users.Add "person4", "group2"
Users.Add "person5", "group2"

'---Add Members of Group 3---
Users.Add "person6", "group3"
Users.Add "person7", "group3"

For Each user In Users.Keys
    If user = UserID Then
        If Users.Item(user) = "group1" Then
            Selection.Font.Color = wdColorRed
        ElseIf Users.Item(user) = "group2" Then
            Selection.Font.Color = wdColorGreen
        ElseIf Users.Item(user) = "group3" Then
            Selection.Font.Color = wdColorBlue
        Else
            Selection.Font.Color = wdColorBlack
        End If
    End If
Next

End Sub
도움이 되었습니까?

해결책

AFAIK, 특정 사용자에 대한 기본 글꼴 색상을 설정할 수 없습니다. 예를 들어, 파란색으로 설정하고 빨간색 인 문장으로 이동하고 입력 한 경우 파란색 텍스트가 아니라 빨간색 텍스트가 표시되지 않습니다. 커서가있는 위치는 그 문장을 색칠하는 데 사용 된 원래 색상을 선택하기 때문입니다.

사용자의 특정 색상을 설정하려면

  1. Identify a range and set the color for it. 그러나 위에서 언급했듯이 사용자가 다른 범위로 탐색하면 새 색상 설정이 적용되지 않습니다.

  2. Set it for the entire document. 전체 문서에 대해 설정하면 전체 문서의 색상이 변경되며 이것이 원하는 것이 아니라고 확신합니다.

다른 팁

가능한 해결 방법 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 매개 변수, 텍스트 주변 및 기타를 사용하면 새로운 색상이 적용되어야하는지 여부를 정확하게 결정할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top