Mimic word borders and shading option “apply to:” (text) with vba on an inline shape

旧巷老猫 提交于 2019-12-25 07:18:22

问题


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:

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?

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

Edit:

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.


回答1:


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

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

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



来源:https://stackoverflow.com/questions/15770248/mimic-word-borders-and-shading-option-apply-to-text-with-vba-on-an-inline-s

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!