Advertisement
Guest User

IWroteTheDamnBill Macro

a guest
Jan 22nd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Sub IWroteTheDamnBill()
  3. Application.Templates.LoadBuildingBlocks
  4.  
  5. Dim objDoc As Document
  6.  
  7. Set objDoc = ActiveDocument
  8.  
  9.   With objDoc.Styles("Line Number").Font
  10.     .Name = "Times New Roman"
  11.     .Size = 12
  12.     .ColorIndex = wdBlack
  13.   End With
  14.  
  15.     If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
  16.         ActiveWindow.Panes(2).Close
  17.     End If
  18.     If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
  19.         ActivePane.View.Type = wdOutlineView Then
  20.         ActiveWindow.ActivePane.View.Type = wdPrintView
  21.     End If
  22.     ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
  23.     ActiveDocument.AttachedTemplate.BuildingBlockEntries("Page X of Y").Insert Where:=Selection.Range, _
  24.         RichText:=True
  25.     ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
  26.  
  27. With Selection.PageSetup
  28.         With .LineNumbering
  29.             .Active = True
  30.             .StartingNumber = 1
  31.             .CountBy = 1
  32.             .RestartMode = wdRestartContinuous
  33.             .DistanceFromText = wdAutoPosition
  34.         End With
  35.         .Orientation = wdOrientPortrait
  36.         .TopMargin = InchesToPoints(1)
  37.         .BottomMargin = InchesToPoints(1)
  38.         .LeftMargin = InchesToPoints(1)
  39.         .RightMargin = InchesToPoints(1)
  40.         .Gutter = InchesToPoints(0)
  41.         .HeaderDistance = InchesToPoints(0.5)
  42.         .FooterDistance = InchesToPoints(0.5)
  43.         .PageWidth = InchesToPoints(8.5)
  44.         .PageHeight = InchesToPoints(11)
  45.         .FirstPageTray = wdPrinterDefaultBin
  46.         .OtherPagesTray = wdPrinterDefaultBin
  47.         .SectionStart = wdSectionNewPage
  48.         .OddAndEvenPagesHeaderFooter = False
  49.         .DifferentFirstPageHeaderFooter = False
  50.         .VerticalAlignment = wdAlignVerticalTop
  51.         .SuppressEndnotes = False
  52.         .MirrorMargins = False
  53.         .TwoPagesOnOne = False
  54.         .BookFoldPrintingSheets = 1
  55.         .GutterPos = wdGutterPosLeft
  56.     End With
  57.    
  58.    
  59. With ActiveDocument.Styles("Footer")
  60.   .ParagraphFormat.Alignment = wdAlignParagraphCenter
  61. End With
  62.  
  63. Selection.WholeStory
  64. Selection.Font.Color = RGB(0, 0, 0)
  65. Selection.Font.Size = 12
  66. Selection.Font.Name = "Times New Roman"
  67. Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
  68.  Dim revs As Word.Revisions
  69.   Dim rev As Word.Revision, revOld As Word.Revision
  70.   Dim rngDoc As Word.Range
  71.   Dim rngRevNew As Word.Range, rngRevOld As Word.Range
  72.   Dim authMain As String, authNew As String, authOld As String
  73.   Dim bReject As Boolean
  74.  
  75.   bReject = False
  76.   Set rngDoc = ActiveDocument.Content
  77.   Set revs = rngDoc.Revisions
  78.   If revs.Count > 0 Then
  79.     authMain = revs(1).Author
  80.   Else 'No revisions so...
  81.    Exit Sub
  82.   End If
  83.  
  84.   For Each rev In revs
  85.     'rev.Range.Select  'for debugging, only
  86.    authNew = rev.Author
  87.     If rev.Type = wdRevisionInsert Or wdRevisionDelete Then
  88.         Set rngRevNew = rev.Range
  89.         'There's only something to compare if an Insertion
  90.        'or Deletion have been made prior to this
  91.        If Not rngRevOld Is Nothing Then
  92.             'The last revision was rejected, so we need to check
  93.            'whether the next revision (insertion for a deletion, for example)
  94.            'is adjacent and reject it, as well
  95.            If bReject Then
  96.                 If rngRevNew.Start - rngRevOld.End <= 1 And authNew <> authMain Then
  97.                     rev.Reject
  98.                 End If
  99.                 bReject = False 'reset in any case
  100.            End If
  101.  
  102.             'If the authors are the same there's no conflict
  103.            If authNew <> authOld Then
  104.                 'If the current revision is not the main author
  105.                'and his revision is in the same range as the previous
  106.                'this means his revision has replaced that
  107.                'of the main author and must be rejected.
  108.                If authNew <> authMain And rngRevNew.InRange(rngRevOld) Then
  109.                     rev.Reject
  110.                     bReject = True
  111.                 'If the previous revision is not the main author
  112.                'and the new one is in the same range as the previous
  113.                'this means that revision has replaced this one
  114.                'of the main author and the previous must be rejected.
  115.                ElseIf authOld <> authMain And rngRevOld.InRange(rngRevNew) Then
  116.                     revOld.Reject
  117.                     bReject = True
  118.                 End If
  119.             End If
  120.         End If
  121.         Set rngRevOld = rngRevNew
  122.         Set revOld = rev
  123.         authOld = authNew
  124.     End If
  125.  
  126.   Next
  127.  
  128. Dim chgAdd As Word.Revision
  129.  
  130. If ActiveDocument.Revisions.Count = 0 Then
  131.     MsgBox "There are no revisions in this document", vbOKOnly
  132. Else
  133.     ActiveDocument.TrackRevisions = False
  134.     For Each chgAdd In ActiveDocument.Revisions
  135.         If chgAdd.Type = wdRevisionDelete Then
  136.             chgAdd.Range.Font.StrikeThrough = True
  137.             chgAdd.Range.Font.Color = wdColorDarkBlue
  138.             chgAdd.Reject
  139.         ElseIf chgAdd.Type = wdRevisionInsert Then
  140.             chgAdd.Range.Font.Color = wdColorRed
  141.             chgAdd.Range.Font.Underline = wdUnderlineSingle
  142.             chgAdd.Range.Font.Bold = True
  143.             chgAdd.Accept
  144.         Else
  145.             MsgBox ("Unexpected Change Type Found"), vbOKOnly + vbCritical
  146.             chgAdd.Range.Select ' move insertion point
  147.        End If
  148.     Next chgAdd
  149. End If
  150.  
  151.  
  152.  
  153. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement