Hi,
Is it possible to erase lines from a table using VBA, like you would using this tool:
biFhpGS.png
I want to erase specific lines from a table in word.
I tried recording it, but the tool greyed out.
All help is greatly appreciated!
- Jeremy
Hi,
Is it possible to erase lines from a table using VBA, like you would using this tool:
biFhpGS.png
I want to erase specific lines from a table in word.
I tried recording it, but the tool greyed out.
All help is greatly appreciated!
- Jeremy
By using the linestyle:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 11/17/2017 Dim oTbl As Table Set oTbl = Selection.Tables(1) With oTbl.Range .Cells(2).Borders(wdBorderLeft).LineStyle = wdLineStyleNone .Cells(3).Borders(wdBorderBottom).LineStyle = wdLineStyleNone End With lbl_Exit: Exit Sub End Sub
Works like a charm!
Thank you Greg !
Hey,
When I add multiple lines of text to the table once I've removed the lines using VBA,
I get something like this:
etk00Hq.png
However, when using the eraser tool it looks like this:
B0PfX1T.png
Which is how I'd like it to look.
I must me missing something.
This is the code I'm using:
All help is greatly appreciated!Dim T1 As table 'Create the table Set T1 = ActiveDocument.Tables.Add(ActiveDocument.Bookmarks("TABEL").Range.Paragraphs(1).Range, 3, 7, wdWord9TableBehavior, wdAutoFitContent) 'Populate the table T1.Cell(1, 1).Range.Text = frmMood.TitelWerkstuk1.Value 'Fetch Value from Userform Textbox T1.Cell(1, 2).Range.Text = "Beoordeling:" T1.Cell(1, 3).Range.Text = "ZW" T1.Cell(1, 4).Range.Text = "M" T1.Cell(1, 5).Range.Text = "V" T1.Cell(1, 6).Range.Text = "G" T1.Cell(1, 7).Range.Text = "ZG" 'Format Table T1.Rows(1).Select Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter Selection.Font.Bold = True T1.Borders.Enable = True T1.Cell(3, 1).Borders(wdBorderTop).LineStyle = wdLineStyleNone 'Enter text in the Table T1.Cell(2, 1).Range.Text = "This is text" & vbNewLine & "Some more"
- Jeremy
The eraser actually merges internal cells (not just remove the border). Try:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 11/21/2017 Dim T1 As Table 'Create the table Set T1 = ActiveDocument.Tables.Add(ActiveDocument.Bookmarks("TABEL").Range.Paragraphs(1).Range, 3, 7, wdWord9TableBehavior, wdAutoFitContent) 'Populate the table T1.Cell(1, 1).Range.Text = "Blah, blah" 'Fetch Value from Userform Textbox T1.Cell(1, 2).Range.Text = "Beoordeling:" T1.Cell(1, 3).Range.Text = "ZW" T1.Cell(1, 4).Range.Text = "M" T1.Cell(1, 5).Range.Text = "V" T1.Cell(1, 6).Range.Text = "G" T1.Cell(1, 7).Range.Text = "ZG" 'Format Table T1.Rows(1).Select Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter Selection.Font.Bold = True T1.Borders.Enable = True T1.Cell(2, 1).Merge MergeTo:=T1.Cell(Row:=3, Column:=1) 'Enter text in the Table T1.Cell(2, 1).Range.Text = "This is text" & vbNewLine & "Some more" lbl_Exit: Exit Sub End Sub
Thanks once again!
Worked perfectly, thank you
- Jeremy