Examples:Preparing Word Documents using Macros
Applying the Macros
Open the document to convert in Microsoft Word.
Remove the unnecessary parts (revision history, table of contents and so on ) from the document.
Click Developer tab in horizontal toolbar.
Click Macros.
Click New.
In the next window, paste the macro text from here.
Click Run. The conversion starts
Save and Rename the converted document.
Replacing Table Rows with a Heading Imported as summary and Table Row Content
This preparation is usually used when:
The items in the document are stored in many tables.
The table cells are not merged vertically.
You want to do a semantic review after importing the items.
The macro will separate contents of the table row vertically and insert headings with uniform text before each row content. The table will be removed, and only the row contents will be preserved.
Here is the macro text:
Sub AllTablesToHeadings()
'
' AllTablesToHeadings Macro
' Macro created by Jaroslaw Michalak, Sandor Szabo
'
For Each aTable In ActiveDocument.Tables
For Each oRow In aTable.Rows
oRow.Cells(1).Select
With Selection
.InsertParagraphBefore
.InsertBefore "Requirement converted from table cell "
End With
Next oRow
Next aTable

For Each aTable In ActiveDocument.Tables
aTable.ConvertToText wdSeparateByCommas, True
Next aTable

With ActiveDocument.Content.Find
.ClearFormatting
.Text = "Requirement converted from table cell"
With .Replacement
.ClearFormatting
.Style = ActiveDocument.Styles("Heading 3")
End With
.Execute Wrap:=wdFindContinue, Format:=True, Replace:=wdReplaceAll
End With

End Sub
Replacing Table Rows with Text Separated Vertically
This preparation is used when:
The items in the document are stored in many tables.
The table cells are not merged vertically.
The user wants to do semantic review before importing the items.
The macro removes tables and keeps the row content only, separated in multiple new lines. You can review the individual text of the former rows and give a title to each. Then you can format the title as a heading. The heading level can be used to form a parent-child structure.
Here is the macro text:
Sub AllTablesToHeadings()
'
' AllTablesToHeadings Macro
'
'
On Error Resume Next
For Each aTable In ActiveDocument.Tables
For Each oRow In aTable.Rows
oRow.Cells(1).Select
With Selection
.Delete
.InsertBefore vbCr
.InsertBefore vbCr
End With
Next oRow
Next aTable

For Each aTable In ActiveDocument.Tables
aTable.ConvertToText wdSeparateByCommas, True
Next aTable

End Sub
도움이 되셨나요?