Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. Option Explicit
  2. Sub ReplacePara()
  3. Dim Para As Paragraph, Xstr As String, Rng As Range
  4. Dim i As Long, ln As Long, tm As Double, PrCnt As Long
  5. Dim PrvChrSize As Integer, NextChrSize As Integer
  6. Dim PrvChrFont As String, NextChrFont As String
  7. Dim PrvChrItalic As Boolean, NextChrItalic As Boolean
  8. tm = Timer
  9.  
  10. ‘Following measures added to improve performance
  11. ‘but on the contrary it’s found instead of increasing time taken
  12. Application.ScreenUpdating = False
  13. With Options
  14. .Pagination = False
  15. .CheckSpellingAsYouType = False
  16. .CheckGrammarAsYouType = False
  17. End With
  18.  
  19.  
  20. With ActiveDocument
  21. PrCnt = .Paragraphs.Count
  22. Debug.Print PrCnt
  23. For i = .Paragraphs.Count To 1 Step -1
  24. Set Para = .Paragraphs(i)
  25. ln = Para.Range.Characters.Count
  26.  
  27. If ln > 1 Then
  28. With Para.Range.Characters(ln - 1).Font
  29. PrvChrSize = .Size
  30. PrvChrFont = .Name
  31. PrvChrItalic = .Italic
  32. End With
  33.  
  34. If i < .Paragraphs.Count Then
  35. With .Paragraphs(i + 1).Range.Characters(1).Font
  36. NextChrSize = .Size
  37. NextChrFont = .Name
  38. NextChrItalic = .Italic
  39. End With
  40. Else
  41. NextChrSize = 0
  42. NextChrFont = ""
  43. NextChrItalic = False
  44. End If
  45. End If
  46.  
  47. 'Debug.Print i, PrvChrSize, PrvChrFont, NextChrSize, NextChrFont
  48. If (PrvChrSize = 15 And (PrvChrFont = "Arial" Or PrvChrItalic = True)) _
  49. And (NextChrSize = 15 And (NextChrFont = "Arial" Or NextChrItalic)) Then
  50. Para.Range.Characters(ln).Text = " "
  51. End If
  52. .UndoClear
  53. 'If PrCnt < 1000 Then Debug.Print i & "/" & PrCnt
  54. Next
  55. End With
  56.  
  57. With Options
  58. .Pagination = True
  59. .CheckSpellingAsYouType = True
  60. .CheckGrammarAsYouType = True
  61. End With
  62. Application.ScreenUpdating = True
  63. Debug.Print " Seconds taken:" & Timer - tm
  64. End Sub
  65.  
  66. Sub makebig()
  67. Dim Rng As Range, MyRange As Range
  68. Dim Wd As Document
  69. Dim i As Long
  70. Set Wd = ThisDocument
  71. Set Rng = Wd.Content
  72. Rng.Copy
  73.  
  74. For x = 1 To 2000
  75. Set MyRange = Wd.Content
  76. MyRange.EndOf Unit:=wdStory, Extend:=wdMove
  77. MyRange.Paste
  78. Next
  79. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement