What should I do if all the table borders in the world document suddenly disappear?

Source: Internet
Author: User

This problem has already been encountered for the second time. I feel that the office is very unreliable and the documents I have worked hard to write are all well done before. Then I opened them one day and found that all the tables in it have no borders, strange... the most terrible thing is that you need to submit this document immediately. At this time, macros will be used.
First, let's look at a macro that traverses all tables:
Sub hong2 ()
Dim TB as table
With activedocument
For each TB in. Tables

Next
End
End sub
It's easy. We won't go around in circles. Let's get the result directly:

Sub hong2 ()
Dim TB as table
With activedocument
For each TB in. Tables
With TB
With. Borders (wdborderleft)
. Linestyle = wdlinestylesingle
. Linewidth = wdlinewidth050pt
. Color = wdcolorautomatic
End
With. Borders (wdborderright)
. Linestyle = wdlinestylesingle
. Linewidth = wdlinewidth050pt
. Color = wdcolorautomatic
End
With. Borders (wdbordertop)
. Linestyle = wdlinestylesingle
. Linewidth = wdlinewidth050pt
. Color = wdcolorautomatic
End
With. Borders (wdborderbottom)
. Linestyle = wdlinestylesingle
. Linewidth = wdlinewidth050pt
. Color = wdcolorautomatic
End
With. Borders (wdborderhorizontal)
. Linestyle = wdlinestylesingle
. Linewidth = wdlinewidth050pt
. Color = wdcolorautomatic
End
With. Borders (wdbordervertical)
. Linestyle = wdlinestylesingle
. Linewidth = wdlinewidth050pt
. Color = wdcolorautomatic
End
. Borders (wdborderdiagonaldown). linestyle = wdlinestylenone
. Borders (wdborderdiagonalup). linestyle = wdlinestylenone
. Borders. Shadow = false
End
Next
End
With options
. Defaultborderlinestyle = wdlinestylesingle
. Defaultborderlinewidth = wdlinewidth050pt
. Defaultbordercolor = wdcolorautomatic
End
End sub

Haha, finished ....

Paste this code into the macro editor and run it. OK, the problem is solved...

Based on this, we can also derive some other macros. The following is what I wrote for the sake of time:
Automatically select all tables:
Sub selectalltables ()
Dim mytable as table
Application. screenupdating = false

For each mytable in activedocument. Tables
Mytable. range. Editors. Add wdeditoreveryone
Next
Activedocument. selectalleditableranges (wdeditoreveryone)
Activedocument. deletealleditableranges (wdeditoreveryone)
Application. screenupdating = true
End sub

Traverse all tables and select the headers in sequence:
Sub selecttableheader ()
Dim TB as table
With activedocument
For each TB in. Tables
. Range (Tb. Cell (1, 1). range. Start, TB. Cell (1, TB. Columns. Count). range. End). Select
Next
End
End sub

Traverse all headers and set the header background to light gray:
Sub hong3 ()
Dim TB as table
With activedocument
For each TB in. Tables
. Range (Tb. Cell (1, 1). range. Start, TB. Cell (1, TB. Columns. Count). range. End). Select
Selection. shading. backgroundpatterncolor = wdcolorgray20
Next
End
End sub
The following code implements the same function:
Sub hong4 ()
Dim TB as table
With activedocument
For each TB in. Tables
. Range (Tb. Cell (1, 1). range. Start, TB. Cell (1, TB. Columns. Count). range. End). shading. backgroundpatterncolor = wdcolorgray20
Next
End
End sub
The following code sets the font and color of the header:
Sub hong5 ()
Dim TB as table
With activedocument
For each TB in. Tables
. Range (Tb. Cell (1, 1). range. Start, TB. Cell (1, TB. Columns. Count). range. End). Font. Color = wdcolorred
. Range (Tb. Cell (1, 1). range. Start, TB. Cell (1, TB. Columns. Count). range. End). Font. size = 9
Next
End
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.