从Excel VBA中设置单词表格边框

我正在尝试从Excel VBA中设置单词表的边框。 许多网站build议如下:

wrdTable.Borders(wdBorderTop).LineStyle = wdLineStyleSingle 

但是在尝试时出现错误(集合中请求的成员不存在)。 不过,我可以使用下面的代码带内部边框:

 wrdTable.Borders(xlDiagonalUp).LineStyle = xlContinuous 

同样我也试过:

 wrdTable.Borders(xlEdgeTop).LineStyle = xlContinuous 

带来顶部边界,但我得到对angular线。 我怎么能在我的单词表中应用边界(内部和外部边界)? 我正在使用Office 2007。

这些文章将把你放在正确的轨道上:

http://www.shaunakelly.com/word/formatting/border-basics.html

http://www.shaunakelly.com/word/styles/borders-in-table-styles.html

假设你的wrdTable被正确设置为msword文档中的表格对象,你有几个select:

 wrdTable.Borders.Enable = True 

将其设置为True将对象的边框设置为与此对象的当前默认边框属性相同的线条样式和线条宽度。

否则指导方针是

  • 首先设置.LineStyle。
  • 只有.LineStyle不是wdLineStyleNone的话
    • 设置.LineWidth
    • 设置.Color。

inheritance人更详细的版本:

 With wrdTable.Borders .OutsideLineStyle = wdLineStyleSingle .OutsideLineWidth = wdLineWidth075pt .OutsideColor = wdDarkRed End With 

有关语法的其他参考,请参阅此页:

http://msdn.microsoft.com/en-us/library/office/aa221392(v=office.11​​).aspx

(注意,我从手机上input了这段代码,所以没有经过testing)

在“Microsoft Visual Basic”中select菜单“工具” – >“参考”,然后激活“Microsoft Word xx.x对象库”。 然后

 wrdTable.Borders(wdBorderTop).LineStyle = wdLineStyleSingle 

将工作。

我也在寻找相同的function几个小时。