2016-07-27 111 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

如果您逐句通过您的代码,那么该行会发生错误? –

相关问题