Word提供了一个强大的文本转表格的功能,结合VBA可以实现文本快速转换表格。
示例文档如下所示。
现在需要将上述文档内容转换为如下格式的表格,表格内容的起始标志为@@@
。
示例代码如下。
Sub SearchTab()
Application.DefaultTableSeparator = "*"
Selection.HomeKey unit:=wdStory
With Selection.Find
.Text = "@@@"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchAllWordForms = False
Do While .Execute
With Selection
.Delete
.Expand wdParagraph
.Font.Italic = True
.Range.Font.TextColor.RGB = RGB(97, 146, 0)
.MoveDown unit:=wdParagraph