可能な回避策のベース 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.上記のサブを1回実行するか、コードが追加された場合にドキュメントを開きます Document_open event
.
- -編集 - - (以下の@SIDからのいくつかのコメントの後)
提案されたソリューションを使用することには不便があります。しかし、それらのほとんどはいくつかを追加することで解決できます If statements
中身 WindowSelectionChange event
. 。の位置を確認します Sel range
パラメーター、周りのテキスト、その他を使用すると、新しい色を適用すべきかどうかを正確に決定できます。