View Full Version : [SOLVED:] Erase Table line in VBA
Jer3miah
11-17-2017, 08:41 AM
Hi,
Is it possible to erase lines from a table using VBA, like you would using this tool:
20974
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
gmaxey
11-17-2017, 10:07 AM
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
Jer3miah
11-20-2017, 03:40 AM
Works like a charm!
Thank you Greg :)!
Jer3miah
11-21-2017, 06:18 AM
Hey,
When I add multiple lines of text to the table once I've removed the lines using VBA,
I get something like this:
20995
However, when using the eraser tool it looks like this:
20994
Which is how I'd like it to look.
I must me missing something.
This is the code I'm using:
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"
All help is greatly appreciated!
- Jeremy
gmaxey
11-21-2017, 07:06 AM
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
Jer3miah
11-21-2017, 08:04 AM
Thanks once again!
Worked perfectly, thank you :)
- Jeremy
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.