2016-07-27 112 views
1

有沒有方法在Word中的每個圖像周圍添加邊框?我知道我可以創建一個帶有邊框的自定義段落樣式,並把圖像中出現,但也許我可以指定一個全球性的影像風格,就像在CSS:在Word文檔中的每個圖像周圍繪製邊框

img { border: 1px solid #000 } 

回答

0

不幸的是,沒有畫面風格概念在Word中可用。因此,類似於CSS的圖像指定全局樣式是不可能的。

你可以做的是編寫一個VBA宏,爲所有圖像添加邊框。該代碼是有點不同,這取決於你的形象是否格式化文本(InlineShape)或浮動(Shape)是內聯:

Sub AddBorderToPictures() 

    ' Add border to pictures that are "inline with text" 
    Dim oInlineShape As inlineShape 
    For Each oInlineShape In ActiveDocument.InlineShapes 
     oInlineShape.Borders.Enable = True 
     oInlineShape.Borders.OutsideColor = wdColorBlack 
     oInlineShape.Borders.OutsideLineWidth = wdLineWidth100pt 
     oInlineShape.Borders.OutsideLineStyle = wdLineStyleSingle 
    Next 

    ' Add border to pictures that are floating 
    Dim oShape As shape 
    For Each oShape In ActiveDocument.Shapes 
     oShape.Line.ForeColor.RGB = RGB(0, 0, 0) 
     oShape.Line.Weight = 1 
     oShape.Line.DashStyle = msoLineSolid 
    Next 

End Sub 

如果線寬顯然設置wdLineWidth100pt是一個問題,你可以嘗試使用實際的基礎整數值代替,例如:

oInlineShape.Borders.OutsideLineWidth = 8 

這是怎樣的常數被定義:

public enum WdLineWidth 
{ 
    wdLineWidth025pt = 2, 
    wdLineWidth050pt = 4, 
    wdLineWidth075pt = 6, 
    wdLineWidth100pt = 8, 
    wdLineWidth150pt = 12, 
    wdLineWidth225pt = 18, 
    wdLineWidth300pt = 24, 
    wdLineWidth450pt = 36, 
    wdLineWidth600pt = 48, 
} 
+0

這聽起來非常PR omising,謝謝。我可以將此代碼添加到docx文件,以便每次在Word中打開文件時自動執行它? (對不起,我多年沒有使用VBA宏。) –

+0

我試圖在Word 365 Mac中將其添加到我的文檔中,但試圖運行它時,出現[運行時錯誤8043](http:// pasteboard .CO/3hRLwGesT.png)。 –

+0

如果您逐句通過您的代碼,那麼該行會發生錯誤? –

相關問題