-
Notifications
You must be signed in to change notification settings - Fork 2
/
QualtricsToolsFormatting.bas
2416 lines (1864 loc) · 70.3 KB
/
QualtricsToolsFormatting.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "QualtricsTools"
''Updated 4/12/17
Sub define_table_styles()
'After defining table styles, you MUST edit table style
'to uncheck "allow spacing between cells" box!
Call Define_Matrix_Style
Call define_appendix_table_style
Call define_basic_table_style
Call define_question_style
End Sub
Sub format_survey_preview()
'This macro should be used BEFORE any manual updates to the survey preview
Dim i As Integer
Dim ncol As Integer
Dim nrow As Integer
Dim nTables As Integer
'This calls the formatting macros in order
'Change global font and spacing, format title header
Call Preview_Style_Change
Call replace_newline
Call RemoveEmptyParagraphs
Call number_of_respondents
Call Insert_OIRE
Call Insert_logo
Call Insert_footer
With ActiveDocument
nTables = .Tables.count
For i = 1 To nTables
ncol = .Tables(i).Columns.count
nrow = .Tables(i).Rows.count
Debug.Print ncol
.Tables(i).AllowPageBreaks = False
'We have one macro that will iterate through each table and perform
'the appropriate formatting functions
Call format_preview_tables(i, nrow, ncol)
Call Replace_zeros(i)
Call Replace_NaN(i)
Call format_See_Appendix(i)
Next
End With
End Sub
Sub finish_clean_preview()
' This macro should be run AFTER the human components are finished
' This will number questions and delete question export tags from each table
' These macros can also easily be run separately, as long as the numbering is run first
' These apply ONLY to question info rows, so we can take advantage of this
Call number_questions
Call remove_denominatorRow
Call Remove_Export_Tag
End Sub
Sub format_appendix()
'
' Macro that will call all the steps required to format appendix tables
' for coded and raw text appendices
With ActiveDocument
Call Preview_Style_Change
Call replace_newline
Call RemoveEmptyParagraphs
Dim nTables As Long
nTables = .Tables.count
Debug.Print nTables
Dim i As Integer
For i = 1 To nTables
Dim celltxt As String
celltxt = .Tables(i).Cell(4, 1).Range.Text
If InStr(1, celltxt, "Coded Comments") Then
isCodedComment = True
Else
isCodedComment = False
End If
.Tables(i).Select
Selection.ClearParagraphAllFormatting
Selection.EndOf
nrow = .Tables(i).Rows.count
ncol = .Tables(i).Columns.count
'Remove text from second column of coded comment table header
Call duplicateHeaderText(i)
If (nrow >= 6) Then
'set widths for each table
.Tables(i).PreferredWidthType = wdPreferredWidthPercent
.Tables(i).PreferredWidth = 100
'Sort tables alphabetically for plain text, by N then alphabetically for coded
Call alphabetize_table(i)
.Tables(i).Style = "Appendix_style_table"
'Align text vertically to be centered
'Ideally this would be a part of the table style, but I couldn't find it....
.Tables(i).Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.Tables(i).Rows.HeightRule = wdRowHeightAuto
If ncol = 1 Then
.Tables(i).ApplyStyleLastRow = False
.Tables(i).ApplyStyleLastColumn = False
ElseIf ncol = 2 And isCodedComment = True Then
'Verify that it's a coded comment table
.Tables(i).ApplyStyleLastRow = True
.Tables(i).ApplyStyleLastColumn = True
.Tables(i).Columns(2).Select
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(0.55)
Selection.EndOf
Else
.Tables(i).ApplyStyleLastRow = False
.Tables(i).ApplyStyleLastColumn = False
End If
For j = 1 To 6
.Tables(i).Rows(j).Select
If j < 4 Then
With Selection
.Font.Bold = True
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
End With
ElseIf j = 4 Then
With Selection
.Font.Italic = True
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
End With
ElseIf j = 5 Then
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
ElseIf j = 6 Then
With Selection
.Font.Bold = True
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
End With
If ncol = 2 Then
.Tables(i).Cell(j, 2).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End If
End If
Next
Call Appendix_Merge_Header(i)
Set rptHeadCells = .Range(Start:=.Tables(i).Cell(1, 1).Range.Start, _
End:=.Tables(i).Cell(3, ncol).Range.End)
'Make the first 6 rows into a header that will repeat across pages
rptHeadCells.Rows.HeadingFormat = True
'Need to add back side border to "responses" line
'Also repeat bottom border so that it will exist if the table breaks
'across multiple pages
.Tables(i).Rows(3).Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Tables(i).Rows(3).Borders(wdBorderRight).LineStyle = wdLineStyleSingle
.Tables(i).Rows(3).Borders(wdBorderVertical).LineStyle = wdLineStyleSingle
.Tables(i).Rows(3).Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
End If
Next
End With
Call Insert_footer
'Make sure the stupid footer is the correct width...
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1)
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 100
End With
End Sub
Sub finish_clean_appendix()
'This macro should be run AFTER the human components are finished
'Removes the Export and Response Tags
Call Remove_Export_Tag
Call Remove_Response_Tag
End Sub
Sub Preview_Style_Change()
'First step in formatting preview
'Change global font and spacing for the document
'Change paragraph spacing to have no space before or after
'With HTML export, we need a few additional steps
'Lauren discovered these in the senior survey; individual macros written
' and sent 11/17/16; incorporated 12/1/16
'Specify Header 5 (block headers) to be Italic, Bold, size 14 font
On Error Resume Next
With ActiveDocument
With .PageSetup
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.HeaderDistance = InchesToPoints(0.2)
.FooterDistance = InchesToPoints(0.2)
End With
.Paragraphs.SpaceAfterAuto = False
.Paragraphs.SpaceBeforeAuto = False
.Paragraphs.SpaceBefore = 0
.Paragraphs.SpaceAfter = 0
.Paragraphs.Format.Alignment = wdAlignParagraphLeft
'Change style of title (Heading 4), Block names (Header 5), and regular text (Compact)
With .Styles("Heading 4")
With .Font
.Name = "Arial"
.Size = 16
.Color = wdColorAutomatic
End With
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.ParagraphFormat.SpaceAfter = 0
.ParagraphFormat.SpaceBefore = 0
End With
With .Styles("Heading 5").Font
.Name = "Arial"
.Size = 14
.Color = wdColorAutomatic
.Italic = True
.Bold = True
.Underline = False
End With
With .Styles("Heading 5").ParagraphFormat
.SpaceAfter = 0
.SpaceBefore = 0
End With
With .Styles("Compact").Font
.Name = "Arial"
.Size = 10
.Color = wdColorAutomatic
End With
With .Styles("Normal")
With .Font
.Name = "Arial"
.Size = 10
.Color = wdColorAutomatic
End With
.ParagraphFormat.SpaceAfter = 0
.ParagraphFormat.SpaceBefore = 0
End With
With .Sections(1).Footers(wdHeaderFooterPrimary).Range
.Paragraphs.SpaceBefore = 0
.Paragraphs.SpaceAfter = 0
.ParagraphFormat.LineSpacingRule = wdLineSpacingSingle
End With
'Find "Number of Respondents", select line, and change font to 10
'.Wrap = wdFindContinue will find this regardless of where the cursor is in the doc
End With
End Sub
Sub number_of_respondents()
With ActiveDocument
With Selection.Find
.Text = "Number of Respondents: "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
End With
Selection.Find.Execute
Selection.Expand wdLine
Selection.Font.Size = 10
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
End Sub
Sub Insert_OIRE()
'
' Moves to the upper right hand corner and inserts, then formats, text
' This is inserted as style Heading 4 to match Survey name;
' this is then adjusted when we change the format of Heading 4 in Preview_Style_Change
' Created by Adam Kaminski, summer 2016
' Edits by ECM
With ActiveDocument
'Move to the top right of the page
Selection.HomeKey Unit:=wdStory
Selection.TypeParagraph
Selection.HomeKey Unit:=wdStory
Selection.Style = ActiveDocument.Styles("Heading 4")
Selection.Font.Bold = True
Selection.Font.Italic = False
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
'Insert text
oireName = "Office of Institutional" + Chr(10) + "Research & Evaluation" + Chr(10)
Selection.TypeText Text:=oireName
End With
End Sub
Sub Insert_logo()
'
' Inserts the Tufts logo in the upper left hand corner
' Created by Adam Kaminski, summer 2016
' Edits by ECM
With ActiveDocument
'Navigate to the top of the page
Selection.HomeKey Unit:=wdStory
'Pick an image via its path and insert it
Selection.InlineShapes.AddPicture FileName:= _
"Q:\Student Work\Emma's Student Work\Report Generation\Report Macros_Adam\tufts_logo_black.png" _
, LinkToFile:=False, SaveWithDocument:=True
'Select the image
ActiveDocument.InlineShapes(1).Select
'format the image (lock aspect ratio and adjust height)
With Selection.InlineShapes(1)
.LockAspectRatio = msoTrue
.Height = 35
End With
'Move it to the upper left hand corner (0, 0)
Set nShp = Selection.InlineShapes(1).ConvertToShape
With .Shapes(1)
.Top = 0
.Left = 0
End With
End With
End Sub
Sub Insert_footer()
'
' Inserts a footer
'As written, assumes there is only one section; if this changes, we need to uncomment these lines
' Dim i As Long
' For i = 1 To ActiveDocument.Sections.Count
' For Each Section In ActiveDocument.Sections
' Dim myfooter As Word.Range
'Clear the footer if anything exists
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Select
Selection.Delete
'In the event that we are JUST using this function, we need to change the style and format
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
.Paragraphs.SpaceBefore = 0
.Paragraphs.SpaceAfter = 0
.ParagraphFormat.LineSpacingRule = wdLineSpacingSingle
.Font.Name = "Arial"
.Font.Size = 9
End With
Dim footerTable As Table
With ActiveDocument
Set insert_footerTable = .Tables.Add(.Sections(1).Footers(wdHeaderFooterPrimary).Range, 2, 3)
Dim oireFooter As String
Dim analystFooter As String
Dim internalUse As String
oireFooter = "Office of Institutional Research & Evaluation" + _
Chr(10) + "NAME OF SURVEY, YEAR, AND SPECIAL POPULATION (IF APPLICABLE)"
analystFooter = "Prepared by: ANALYST NAME" + Chr(10) + _
"INSERT DATE"
internalUse = "**This report is intended for internal use only**"
Set footerTable = .Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1)
With footerTable
.TopPadding = InchesToPoints(0.08)
.BottomPadding = InchesToPoints(0)
.LeftPadding = InchesToPoints(0)
.RightPadding = InchesToPoints(0)
With .Cell(1, 1).Range
.Text = oireFooter
.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
.Cell(1, 2).Range.Select
Selection.Collapse
With Selection
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PAGE ", PreserveFormatting:=True
.TypeText Text:=" of "
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"NUMPAGES ", PreserveFormatting:=True
End With
.Cell(1, 2).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
With .Cell(1, 3).Range
.Text = analystFooter
.ParagraphFormat.Alignment = wdAlignParagraphRight
End With
.Cell(2, 1).Range.Text = internalUse
'Remove borders from the footer table
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
End With
'Merge cells of second row and format text to be centered and italicized
Dim mrgrng As Range
Set mrgrng = footerTable.Cell(2, 1).Range
mrgrng.End = footerTable.Cell(2, 3).Range.End
mrgrng.Cells.Merge
footerTable.Rows(2).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Italic = True
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
End With
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1)
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 100
.Cell(1, 2).PreferredWidthType = wdPreferredWidthPercent
.Cell(1, 2).PreferredWidth = 12
.Cell(1, 1).PreferredWidthType = wdPreferredWidthPercent
.Cell(1, 1).PreferredWidth = 44
.Cell(1, 3).PreferredWidthType = wdPreferredWidthPercent
.Cell(1, 3).PreferredWidth = 44
.Rows.LeftIndent = InchesToPoints(0)
End With
End Sub
Sub format_preview_tables(i As Integer, nrow As Integer, ncol As Integer)
If ncol = 1 Then
Call format_question_info(i, nrow)
ElseIf ncol = 3 Then
Call format_mc_singleQ(i, nrow, ncol)
ElseIf ncol > 3 Then
Call format_matrix_table(i, nrow, ncol)
End If
End Sub
Sub define_basic_table_style()
On Error Resume Next
ActiveDocument.Styles("basic_table_style").Delete
ActiveDocument.Styles.Add Name:="basic_table_style", Type:=wdStyleTypeTable
With ActiveDocument.Styles("basic_table_style")
With .Table
.AllowPageBreaks = False
.AllowBreakAcrossPage = False
End With
End With
With ActiveDocument.Styles("basic_table_style").ParagraphFormat
.LeftIndent = InchesToPoints(0.08)
.RightIndent = InchesToPoints(0.08)
End With
End Sub
Sub define_question_style()
On Error Resume Next
ActiveDocument.Styles("question_style").Delete
ActiveDocument.Styles.Add Name:="question_style", Type:=wdStyleTypeTable
With ActiveDocument.Styles("question_style")
With .Table
.AllowPageBreaks = False
.AllowBreakAcrossPage = False
End With
End With
End Sub
Sub format_question_info(i As Integer, nrow As Integer)
'Format question text and information
With ActiveDocument
.Tables(i).Style = "question_style"
'format the question info, identified by single column
' Set table width to full page
.Tables(i).PreferredWidthType = wdPreferredWidthPercent
.Tables(i).PreferredWidth = 100
With .Tables(i)
.Spacing = InchesToPoints(0)
.TopPadding = InchesToPoints(0)
.BottomPadding = InchesToPoints(0)
.LeftPadding = InchesToPoints(0)
.RightPadding = InchesToPoints(0)
End With
'Bold question text
.Tables(i).Rows(2).Select
With Selection
.Font.Bold = True
End With
'Make display logic red to highlight
If nrow >= 3 Then
Dim r As Long
For r = 3 To nrow
.Tables(i).Rows(r).Select
With Selection.Font
.Bold = True
.Color = wdColorDarkRed
End With
Next
End If
' Stop table from breaking across page
End With
End Sub
Sub format_mc_singleQ(i As Integer, nrow As Integer, ncol As Integer)
With ActiveDocument
.Tables(i).Style = "basic_table_style"
Dim nRows As Long
Dim nCols As Long
nRows = .Tables(i).Rows.count
nCols = .Tables(i).Columns.count
For j = 1 To nRows
For k = 1 To nCols
.Tables(i).Cell(j, k).TopPadding = 0
.Tables(i).Cell(j, k).BottomPadding = 0
.Tables(i).Cell(j, k).LeftPadding = 0
.Tables(i).Cell(j, k).RightPadding = 0
Next
Next
'Adjust cell padding for multiple choice
With .Tables(i)
.LeftPadding = InchesToPoints(0)
.RightPadding = InchesToPoints(0)
.TopPadding = InchesToPoints(0.01)
.BottomPadding = InchesToPoints(0.01)
.Spacing = InchesToPoints(0)
End With
.Tables(i).Select
'Remove inside borders
Selection.Borders.InsideLineStyle = wdLineStyleNone
'Select N column
'Adjust font and right align
.Tables(i).Columns(1).Select
With Selection
With .Font
.Bold = True
.Italic = True
.Color = wdColorGray40
End With
With .ParagraphFormat
.Alignment = wdAlignParagraphRight
End With
End With
'Select % column
'Bold and right align
.Tables(i).Columns(2).Select
With Selection
.Font.Bold = True
.ParagraphFormat.Alignment = wdAlignParagraphRight
End With
'Delete first row from this type of question
.Tables(i).Rows(1).Select
Selection.Rows.Delete
End With
End Sub
Sub Define_Matrix_Style()
'If the style exists from a previous run, delete and redefine
On Error Resume Next
ActiveDocument.Styles("Matrix_table_style").Delete
ActiveDocument.Styles.Add Name:="Matrix_table_style", Type:=wdStyleTypeTable
With ActiveDocument.Styles("Matrix_table_style")
With .Table
.RowStripe = 1
.ColumnStripe = 0
.AllowPageBreaks = False
.AllowBreakAcrossPage = False
With .Condition(wdEvenRowBanding)
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = -738132173
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
End With
End With
End Sub
Sub format_matrix_table(i As Integer, nrow As Integer, ncol As Integer)
With ActiveDocument
With .Tables(i)
.Style = "Matrix_table_style"
.LeftPadding = InchesToPoints(0)
.RightPadding = InchesToPoints(0)
.TopPadding = InchesToPoints(0.01)
.BottomPadding = InchesToPoints(0.01)
.Spacing = InchesToPoints(0)
End With
With .Tables(i).Cell(1, 1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleNone
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleNone
End With
End With
.Tables(i).PreferredWidthType = wdPreferredWidthPercent
.Tables(i).PreferredWidth = 100
.Tables(i).Columns(1).Select
With Selection.Cells
.SetWidth _
ColumnWidth:=InchesToPoints(3.5), _
RulerStyle:=wdAdjustNone
End With
'Format N columns
Dim nColumns As Long
nColumns = .Tables(i).Columns.count
For j = 1 To nColumns
.Tables(i).Columns(j).Select
Selection.Find.ClearFormatting
With Selection.Find
.Text = "N"
.MatchWholeWord = True
End With
Selection.Find.Execute
If Selection.Find.Found = True Then
.Tables(i).Columns(j).Select
With Selection.Cells
.SetWidth _
ColumnWidth:=InchesToPoints(0.47), _
RulerStyle:=wdAdjustNone
End With
With Selection.Font
.Bold = True
.Italic = True
.Color = wdColorGray40
End With
With Selection.ParagraphFormat
.Alignment = wdAlignParagraphCenter
End With
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
End If
Next
'Format percentage columns
Dim PerColumns As Long
PerColumns = .Tables(i).Columns.count
For k = 1 To PerColumns
.Tables(i).Columns(k).Select
Selection.Paragraphs.LeftIndent = InchesToPoints(0.08)
Selection.Paragraphs.RightIndent = InchesToPoints(0.08)
Selection.Find.ClearFormatting
With Selection.Find
.Text = "%"
.MatchWholeWord = False
End With
Selection.Find.Execute
If Selection.Find.Found = True Then
.Tables(i).Columns(k).Select
With Selection.Cells
.PreferredWidth = None
End With
With Selection.Font
.Bold = True
.Italic = False
.Color = wdColorAutomatic
End With
With Selection.ParagraphFormat
.Alignment = wdAlignParagraphCenter
End With
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
End If
Next
'Center align test horizontal and vertical
'Format header
.Tables(i).Rows(1).Select
With Selection.Font
.Bold = True
.Italic = False
.Color = wdColorAutomatic
End With
With Selection.ParagraphFormat
.Alignment = wdAlignParagraphCenter
End With
With Selection.Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
End With
End Sub
Sub Replace_zeros(i As Integer)
'
' Searches for "0.0%" and replaces it with "--"
' Created by Adam Kaminsky
' Edited by EM to make sure the program didn't stop part of the way through
Application.DisplayAlerts = False
ActiveDocument.Tables(i).Range.Select
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "0.0%"
.Replacement.Text = "--"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.MatchPrefix = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Next
End Sub
Sub Replace_NaN(i As Integer)
'
' Searches for "NaN%" resulting from denominator 0 and replaces it with "--"
' Adapted from "Replace 0" code
' Created by Adam Kaminsky
' Edited by EM to make sure the program didn't stop part of the way through
Application.DisplayAlerts = False
ActiveDocument.Tables(i).Range.Select
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "NaN%"
.Replacement.Text = "--"
.Forward = True
.Wrap = wdFindStop