从 Excel VBA 设置单词表边框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12274228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting word table border from Excel VBA
提问by chemicalkt
I am having trying to set border of word table from Excel VBA. Many sites suggest the following:
我正在尝试从 Excel VBA 设置单词表的边框。许多网站建议如下:
wrdTable.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
but I get an error (The requested member of the collection does not exist) while trying it. However, I could bring inner borders using following code:
但是在尝试时出现错误(集合的请求成员不存在)。但是,我可以使用以下代码带内边框:
wrdTable.Borders(xlDiagonalUp).LineStyle = xlContinuous
Similarly I tried:
同样我试过:
wrdTable.Borders(xlEdgeTop).LineStyle = xlContinuous
to bring top borders, but I get diagonal lines. How could I apply borders (inner and outside borders) in my word tables? I am using office 2007.
带上边框,但我得到对角线。如何在我的单词表中应用边框(内边框和外边框)?我正在使用 Office 2007。
回答by danielpiestrak
These articles will put you on the right track:
这些文章将使您走上正轨:
http://www.shaunakelly.com/word/formatting/border-basics.html
http://www.shaunkelly.com/word/formatting/border-basics.html
http://www.shaunakelly.com/word/styles/borders-in-table-styles.html
http://www.shaunkelly.com/word/styles/borders-in-table-styles.html
Assuming your wrdTable
is properly set to the table object in msword's document you have a few options:
假设您wrdTable
已正确设置为 msword 文档中的 table 对象,您有几个选项:
wrdTable.Borders.Enable = True
Setting this to True set's the object's borders to the same line style and line width as the current default border properties for this object.
将此设置为 True 将对象的边框设置为与此对象的当前默认边框属性相同的线型和线宽。
Otherwise guidelines are
否则指导方针是
- Set the .LineStyle first.
- Only if .LineStyle is not wdLineStyleNone then
- set the .LineWidth
- set the .Color.
- 首先设置 .LineStyle。
- 仅当 .LineStyle 不是 wdLineStyleNone 时
- 设置 .LineWidth
- 设置.Color。
Heres a more detailed version:
这是更详细的版本:
With wrdTable.Borders
.OutsideLineStyle = wdLineStyleSingle
.OutsideLineWidth = wdLineWidth075pt
.OutsideColor = wdDarkRed
End With
For additional reference on syntax, see this page:
有关语法的其他参考,请参阅此页面:
http://msdn.microsoft.com/en-us/library/office/aa221392(v=office.11).aspx
http://msdn.microsoft.com/en-us/library/office/aa221392(v=office.11).aspx
(note, I've typed this code from my mobile phone, so it is untested)
(请注意,我是从手机输入此代码的,因此未经测试)
回答by vskarlsruhe
Select in "Microsoft Visual Basic" the menu "Tools" -> "References" and activate "Microsoft Word xx.x Object Library". Then
在“Microsoft Visual Basic”中选择菜单“工具”->“参考”并激活“Microsoft Word xx.x 对象库”。然后
wrdTable.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
will work.
将工作。
I was also searching for the same function for hours.
我也在几个小时内寻找相同的功能。