2016-11-07 4 views
1

私は現在MS Wordレポートを作成しています。正確にテキストの高さにワードシェーディング

画像の下に見られるように、特定のセクションを強調表示するには、それがテキストの一部日陰に素晴らしいことだ:

This is what I want to have

は、残念ながら、私はフルラインのシェーディングを追加することができますよ次の図に示すように、高さ、:

This is what I got

は単なるテキストの高さのためにシェーディングを達成するためにMS Wordの内部のネイティブ方法はありますか?

そうでなければ私は見出しとして私のレポート内の画像を埋め込むことを強制しています(これは、目次で例えば合併症、私はいくつかの理由のためにしたくないものです)

答えて

0

シェーディングを持ってする直接的な方法はありませんあなたが望むように、それは常にフルラインの高さでキャップの高さではありません。また、大文字のQや小文字のg(小文字のgなど)のように、シェーディングがどのようにテールのように見えるかについて考えると、意味があります。

シェーディングを1行に追加する場合は

ここでは、選択したテキスト行にシェイプを追加する、すばやく汚れたVBAマクロがあります。細かいことが必要です図形の高さと垂直方向のオフセットを使用するフォントとフォントサイズに合わせて調整します。

Sub AddShading() 
    Dim rng As Range 
    Dim startPos As Integer 
    Dim endPos As Integer 

    Dim capHeight As Single 
    capHeight = 8 

    Dim verticalOffset As Single 
    verticalOffset = 3 

    ' backup original select 
    Set rng = Selection.Range.Duplicate 

    ' start undo transaction 
    Application.UndoRecord.StartCustomRecord "Add Shading" 

    Do 
     ' select line of text 
     Selection.Collapse 
     Selection.Expand wdLine 
     If Selection.Start < rng.Start Then 
      Selection.Start = rng.Start 
     End If 
     If Selection.End > rng.End Then 
      Selection.End = rng.End 
     End If 

     ' get range of current line to be able to retrieve position of line 
     Dim rngLine As Range 
     Set rngLine = Selection.Range.Duplicate 

     ' get the left coordinate 
     Dim left As Single 
     left = rngLine.Information(wdHorizontalPositionRelativeToPage) 

     ' get the top coordinate and add a vertical adjustment depending on the font used 
     Dim top As Single 
     top = rngLine.Information(wdVerticalPositionRelativeToPage) + verticalOffset 

     ' move to the end position of the line 
     rngLine.Collapse wdCollapseEnd 
     If rngLine.Information(wdVerticalPositionRelativeToPage) > top Then 
      rngLine.Move wdCharacter, -1 
     End If 

     ' calculate width of line 
     Dim width As Integer 
     width = rngLine.Information(wdHorizontalPositionRelativeToPage) - left 

     ' add shape behind text 
     Dim shp As Shape 
     Set shp = rng.Document.Shapes _ 
      .AddShape(msoShapeRectangle, left, top, width, capHeight, rng) 

     With shp 
      ' grey shading 
      .Fill.ForeColor.RGB = RGB(192, 192, 192) 

      ' no outline 
      .Line.Visible = msoFalse 

      ' the shape should move with the text 
      .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph 

      ' position the shape behind the text 
      .WrapFormat.Type = wdWrapBehind 
     End With 

     ' continue with next line 
     Selection.Move wdLine 

    Loop While Selection.End < rng.End 

    ' restore original selection 
    rng.Select 

    Application.UndoRecord.EndCustomRecord 

End Sub 
関連する問題