表格边框未在Word文档中显示

时间:2018-03-18 14:57:17

标签: vba vbscript ms-word ms-office word-vba

我花了一些时间试图找到如何在我的表格中添加边框。任何类型的边界(我想我会在我看到它的时候调整它)。)。

我尝试了很多在网上找到的方法,但似乎没有什么能适用于我的情况。这是我的vbscript。

我通过简单的双击(Windows 7 x64)

运行脚本
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
Set objSection = objDoc.Sections(1)

Const NUMBER_OF_ROWS = 3
Const NUMBER_OF_COLUMNS = 4
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS
Set objTable = objDoc.Tables(1)
objTable.Borders.Enable = True
'a way i found on web, does nothing
With objTable.Borders
        .InsideLineStyle = wdLineStyleSingle
        .InsideColor = wdColorAutomatic
        .OutsideLineStyle = wdLineStyleSingle
        .OutsideColor = wdColorAutomatic

    End With

objTable.Cell(1, 1).Range.Text = "ΠΕΡΙΓΡΑΦΗ"
'another way i tried my self, does nothing aswell
objTable.Cell(1, 1).Range.Borders.InsideLineStyle = wdLineStyleSingle
objTable.Cell(1, 1).Range.Borders.InsideColor = wdColorAutomatic
objTable.Cell(1, 1).Range.Borders.InsideLineStyle = wdLineStyleSingle
objTable.Cell(1, 2).Range.Text = "ΗΜΕΡΟΜΗΝΙΑ"
objTable.Cell(1, 3).Range.Text = "ΧΙΛΙΟΜΕΤΡΑ"
objTable.Cell(1, 4).Range.Text = "ΠΑΡΑΤΗΡΗΣΕΙΣ"


objTable.Cell(2, 1).Range.Text = "text text"
objTable.Cell(2, 2).Range.Text = "17/3/2018"
objTable.Cell(2, 3).Range.Text = "10000"
objTable.Cell(2, 4).Range.Text = "text"

objTable.Cell(3, 1).Range.Text = "a text"
objTable.Cell(3, 2).Range.Text = "17/3/2018"
objTable.Cell(3, 3).Range.Text = "10000"
objTable.Cell(3, 4).Range.Text = "a text"


objDoc.SaveAs("C:\Users\George\Desktop\AAA - 4355.docx")
objWord.Quit

1 个答案:

答案 0 :(得分:0)

删除声明

objTable.Borders.Enable = True

并尝试在单元格(1,1)上应用底部边框

objTable.Cell(1, 1).Range.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
objTable.Cell(1, 1).Range.Borders(wdBorderBottom).LineWidth = wdLineWidth050pt
objTable.Cell(1, 1).Range.Borders(wdBorderBottom).Color = wdColorAutomatic