模仿单词边框和底纹选项“应用于:" (文本)与内联形状上的vba [英] Mimic word borders and shading option "apply to:" (text) with vba on an inline shape

查看:76
本文介绍了模仿单词边框和底纹选项“应用于:" (文本)与内联形状上的vba的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个宏,该宏具有一个表,其中第一行是该表的名称,随后的所有行都是粘贴的打印屏幕.宏的作用是,粘贴新的打印屏幕时,图像将被调整为特定大小,并添加了050pt的边框.

I got a macro that has a table with the first row being the name for that table and all the subsequent rows are print screens pasted. What the macro does is that when a new print screen is pasted the image is resized to a specific size and is added a border of 050pt.

有人要求我将边框应用于文本:例如:

I was asked that the border be applied to text: For example:

我在图像上执行的操作是选择整个表,在左上角有一个小十字,右键单击鼠标,选择边框和底纹"选项,最后像这样设置边框格式:.5pt框单线样式.所有这些都很好,问题在于红色框位于何处,如何使用VBA模仿应用于:文本"选项.当您选择该选项时,它会做什么?当图像的行为类似于inlineShape时,如何甚至将边框设置为文本,有没有办法做到这一点?

What I did on the image was select the whole table with the little cross on the upper left hand corner, right click on the mouse, select "Borders & Shading" option and finally format my border like so: .5pt Box single line style. All of this is fine the problem is where the red box lies, how do I mimic with VBA the "Apply to: text" option. When you select that option what does it do? how can you even set the border to text when the image behaves like an inlineShape is there any way to do this?

注意:如您所见,它是Office Word 2010

Note: As you can see it's Office Word 2010

有没有不用Selection的方法吗?问题是我的子对象的工作方式如下:For Each inlineShape in ActiveDocument.InlineShapes要获取文档中的所有形状,还是可以使用For Each将所有形状存储在变量中并将该变量视为Selection?我这样做是为了在对文档进行大量更改之后,该子控件会触发并检查文档中的每个屏幕截图,以便即使进行更改也保持一致.

Is there any way to do it without using Selection? The thing is that my sub works like this: For Each inlineShape in ActiveDocument.InlineShapes To get all shapes in the document or can I use that For Each to store all shapes in a variable and treat that variable as a Selection? I do it like this so that after a number of changes on the document, the sub fires and it checks every screen shot in the document so that it's consistent even if changes are made.

推荐答案

通常,在Word中考虑Range时,我们会想到文本.但是,InlineShapes是文档中Range对象的一部分.文本和InlineShapes都可以带有边框.我的简单想法是,在选择一些文本和/或InlineShape之后尝试此代码.

Mostly, thinking of Range in Word we think of text. However, InlineShapes are part of Range objects in document. Both of them- text and InlineShapes can have borders. My simple idea for you is to try this code after you select some text and/or InlineShape.

Sub BorderingText_InLnShapes()

With Selection.Range
    .Borders(wdBorderTop).LineStyle = wdLineStyleSingle
    .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
    .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
    .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
End With
End Sub

使用宏记录器时,您可能具有类似的宏,该宏引用了Font对象:

When working with macro recorder you could have similar macro which refers to Font object:

Sub Alternative()
'based on recorder
With Selection.Font
    With .Borders(1)
        .LineStyle = wdLineStyleSingle
        .LineWidth = wdLineWidth050pt
        .Color = wdColorAutomatic
    End With
    .Borders.Shadow = False
End With
End Sub

上面的代码与InlineShape的工作原理略有不同,但与文本几乎相同. 我希望这会有所帮助.

The code above works a bit different with InlineShape but almost the same with text. I hope it's a bit helpful.

这篇关于模仿单词边框和底纹选项“应用于:" (文本)与内联形状上的vba的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆