Thread: [Solved] Indexing Macro
View Single Post
 
Old 06-09-2011, 01:17 AM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi mtames1,

Perhaps you could explain what you're trying to achieve with the various kinds of tags. It appears you want to keep all except the '<$I[cat]' and '>' of some, but only a lesser portion of others. If all the tags are all in the format you've described, a single wildcard Find can locate them all. For example:
Find = \<$I\[cat\]([!\>]{1,})\>
Replace = \1

Also, your code has a lot of redundacy in it - there is no need to keep setting the Find/Replace parameters. For example:
Code:
...
Dim myField As Field
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Forward = True
  .Wrap = wdFindStop
  .Format = True
  .MatchCase = False
  .MatchWholeWord = False
  .MatchAllWordForms = False
  .MatchSoundsLike = False
  .MatchWildcards = False
  .Text = "><"
  .Replacement.Text = "> */-/* <"
  .Execute Replace:=wdReplaceAll
  .Replacement.Style = ActiveDocument.Styles("Big Yellow")
  .Text = "[\<]$I\[cat\]([0-9A-Za-z,\-\(\) ]{1,})\[([0-9A-Za-z,\-\(\) ]{1,})\][\>]"
  .Replacement.Text = " \1"
  .Execute Replace:=wdReplaceAll
  .Text = "[\<]$I)[cat\]([0-9A-Za-z,\-\(\) ]{1,})\[([0-9A-Za-z,\-\(\) ]{1,})\];([0-9A-Za-z,\-\(\) ]{1,})\[([0-9A-Za-z,\-\(\) ]{1,})\][\>]"
  .Replacement.Text = " \1:\3"
  .Execute Replace:=wdReplaceAll
End With
myCharStyle = "Big Yellow"
...
PS: When posting code, please use code tags and formatted code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote