Advertisement
Guest User

DreamViews Word Macro

a guest
Sep 11th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.60 KB | None | 0 0
  1. Public Function RemoveSpaces(original) As String
  2.  
  3. RemoveSpaces = Replace(original, " ", "+")
  4.  
  5. End Function
  6.  
  7. Public Function GetProfileName(original) As String
  8.  
  9. If original = "Dreamer" Then
  10.     GetProfileName = "~+dreamer+~"
  11. Else
  12.     GetProfileName = RemoveSpaces(original)
  13. End If
  14.  
  15. End Function
  16.  
  17. Public Function MakeReplacement(original) As String
  18.  
  19. Dim profileName As String
  20. profileName = GetProfileName(original)
  21.  
  22. '[b][url=<stuff>]CanisLucidus[/url][/b]
  23. Dim altered As String
  24. altered = "[b][url=http://www.dreamviews.com/members/" & profileName & "]" & original & "[/url][/b]"
  25. MakeReplacement = altered
  26.  
  27. End Function
  28.  
  29. Sub FindAndReplaceFirstStoryOfEachType()
  30.  
  31. Dim replacements As Variant
  32. replacements = Array( _
  33.     "Dreamer", _
  34.     "Original Poster", _
  35.     "Dark_Merlin", _
  36.     "DUMMY" _
  37. )
  38.  
  39. Dim myStoryRange As Range
  40. Dim currentReplacement As Variant
  41.  
  42. For Each currentReplacement In replacements
  43.     For Each myStoryRange In ActiveDocument.StoryRanges
  44.         With myStoryRange.Find
  45.             .Text = "$$" & currentReplacement
  46.             .replacement.Text = MakeReplacement(currentReplacement)
  47.             .Wrap = wdFindContinue
  48.             .Execute Replace:=wdReplaceAll
  49.         End With
  50.     Next myStoryRange
  51. Next currentReplacement
  52.  
  53. For Each myStoryRange In ActiveDocument.StoryRanges
  54.     With myStoryRange.Find
  55.         .Text = "$$(<*>)"
  56.         .replacement.Text = "[b][url=http://www.dreamviews.com/members/\1]\1[/url][/b]"
  57.         .Wrap = wdFindContinue
  58.         .MatchWildcards = True
  59.         .Execute Replace:=wdReplaceAll
  60.     End With
  61. Next myStoryRange
  62.  
  63. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement