Macros

Create or run a macro

Tables

Create a macro to help standardize the look of tables outside of what can be done by R.

Sub FormatTables()
  If ActiveDocument.Tables.Count > 0 Then
    Dim objTable As Object

    Application.Browser.Target = wdBrowseTable
    For Each objTable In ActiveDocument.Tables
      objTable.AutoFitBehavior (wdAutoFitWindow)
    Next
  End If
End Sub

Put every table on it’s own page

Sub PagePerTable()
'
' PagePerTable Macro
'
'
 
For Each Tbl In ActiveDocument.Tables
    Set myRange = Tbl.Range
    With myRange
        .Collapse Direction:=wdCollapseEnd
        .InsertBreak Type:=wdPageBreak
    End With
    Next
 
End Sub

Figures

This macro reduces the size of all figures in an active document to 45% of its original size.

Sub FormatFigures()

Dim shp As InlineShape

For Each shp In ActiveDocument.InlineShapes
    shp.ScaleHeight = 45
    shp.ScaleWidth = 45
Next

End Sub