![]() |
#1
|
|||
|
|||
![]()
I've got myself into a bit of a muddle with a definitions macro I am trying to put together, I did have help some time ago but have completely forgotten what some of the code does as I stupidly didn't add reminder text within the code for some of it. I need to simplify the code and also remove the quotes and tabs in between words with hyphens, ampersands and brackets. I have attached a document highlighting the issues I'm having and also a document to test the macro on. If anyone can help me I would be eternally grateful.
1. example of issues in definitions macro.docx 2. Test Document for definitions macro.docx Code:
Sub DPU_convertdefinitions() Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting ActiveDocument.Range.ListFormat.ConvertNumbersToText Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = """" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^t" .Replacement.Text = " " .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.ClearFormatting Selection.Find.Font.Bold = True Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "<*>" .Replacement.Text = "^034^&^034^t" .Forward = True .Wrap = wdFindStop .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^034^t ^034" .Replacement.Text = "^032" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll 'remove space after tab' With Selection.Find .Text = "^t " .Replacement.Text = "^t" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p(" .Replacement.Text = "^p^t(" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting 'remove the words means from each definition and insert a tab' With Selection.Find .Text = "^tmeans" .Replacement.Text = "^t" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting 'remove colon after tab' With Selection.Find .Text = "^t:" .Replacement.Text = "^t" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting 'remove comma after tab' With Selection.Find .Text = "^t," .Replacement.Text = "^t" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting 'remove space after tab' With Selection.Find .Text = "^t " .Replacement.Text = "^t" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.Execute Replace:=wdReplaceAll Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting 'replace periods with semi colons at end of each definition' With Selection.Find .Text = ".^p" .Replacement.Text = ";^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Dim oRng As Range Const strText As String = "^13[A-Za-z]" Set oRng = ActiveDocument.Range With oRng.Find Do While .Execute(FindText:=strText, MatchWildcards:=True) If oRng.Paragraphs(2).Style = "Normal" And _ oRng.Paragraphs(2).Range.Characters(1).Font.Bold = False Then oRng.Paragraphs(2).Range.InsertBefore vbTab End If oRng.Collapse 0 Loop End With lbl_Exit: Set oRng = Nothing Exit Sub End Sub |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Johnmajor | Word VBA | 20 | 02-18-2020 06:59 PM |
Spell check macro within macro button field doesn't work in one document | samuelle | Word VBA | 0 | 07-20-2016 02:27 AM |
![]() |
philpense | Word | 1 | 02-23-2015 04:34 PM |
![]() |
ChrisBrewster | Word VBA | 2 | 02-10-2014 10:33 AM |
Problem: object library invalid or contains references to object definitions | aligahk06 | Office | 0 | 08-19-2010 12:29 PM |