Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
I am using Word 2003, but if I can successfully figure out how to do this, I
would also like to be able to do the same on Word 2004 for Mac. I am trying to figure out a way to automate replacing numbers in page ranges to match the Chicago Manual of Style. For instance, I need to change 149-167 to 149-67, but not 149-249 to 149-49 or not 106-108 to 106-08 (instead that should go to 106-8). I'm not sure I have thought out all the exceptions, though these are the most basic. I am mainly looking for the methodology to use, whether through find and replace or macros. I don't want to spend too much time trying to figure it out, because I'm not sure the return will be worth a lot of time invested. I know that by using wildcard search and replace I can do most of this. For instance, I could search for ([!0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9]) and replace with \1\2\3\4\\5\6, replacing something like 125126 to "12526. But that doesn't help me with all because I would still have to make adjustments for the above-mentioned exceptions. If automating using macros is the best choice, I would also like to figure out a way to double-check that changes were made correctly and there were no mistakes. So is it possible to write into the macro (if doing a macro) to copy all replacements (or all things being replaced) into a blank word document to be able to quickly scan all instances of replacements? Or to highlight all changes made in the document to be able to quickly pick up what was changed? Does this make sense? Can anyone help? Thanks. |
#2
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
The following macro deals with the case that you mention:
Dim numrange As Range, numrange1 As Range, numrange2 As Range Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="[0-9]{1,}-[0-9]{1,}", MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True Set numrange = Selection.Range Selection.Range.Collapse wdCollapseEnd Set numrange1 = numrange.Duplicate Set numrange2 = numrange.Duplicate numrange1.End = numrange1.Start + InStr(numrange1, "-") - 1 numrange2.Start = numrange2.Start + InStr(numrange2, "-") If Len(numrange1) = Len(numrange2) Then If Left(numrange1, 1) = Left(numrange2, 1) Then If Mid(numrange1, 2, 1) = Mid(numrange2, 2, 1) Then numrange = numrange1 & "-" & Mid(numrange2, 3) Else numrange = numrange1 & "-" & Mid(numrange2, 2) End If End If End If Loop End With -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "JeremyC" wrote in message ... I am using Word 2003, but if I can successfully figure out how to do this, I would also like to be able to do the same on Word 2004 for Mac. I am trying to figure out a way to automate replacing numbers in page ranges to match the Chicago Manual of Style. For instance, I need to change 149-167 to 149-67, but not 149-249 to 149-49 or not 106-108 to 106-08 (instead that should go to 106-8). I'm not sure I have thought out all the exceptions, though these are the most basic. I am mainly looking for the methodology to use, whether through find and replace or macros. I don't want to spend too much time trying to figure it out, because I'm not sure the return will be worth a lot of time invested. I know that by using wildcard search and replace I can do most of this. For instance, I could search for ([!0-9])([0-9])([0-9])([0-9])-([0-9])([0-9])([0-9]) and replace with \1\2\3\4\-\5\6, replacing something like " 125-126" to "125-26." But that doesn't help me with all because I would still have to make adjustments for the above-mentioned exceptions. If automating using macros is the best choice, I would also like to figure out a way to double-check that changes were made correctly and there were no mistakes. So is it possible to write into the macro (if doing a macro) to copy all replacements (or all things being replaced) into a blank word document to be able to quickly scan all instances of replacements? Or to highlight all changes made in the document to be able to quickly pick up what was changed? Does this make sense? Can anyone help? Thanks. |
#3
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Thanks. Will that make exceptions for numbers such as 200-204, which should
not be shortened, or for 202-204, which should be shortened to 202-4? Also, will that create notation to show which numbers were changed? I'm thinking that it won't work for these special circumstances, but perhaps I can figure out how to modify it do so. "JeremyC" wrote: I am using Word 2003, but if I can successfully figure out how to do this, I would also like to be able to do the same on Word 2004 for Mac. I am trying to figure out a way to automate replacing numbers in page ranges to match the Chicago Manual of Style. For instance, I need to change 149-167 to 149-67, but not 149-249 to 149-49 or not 106-108 to 106-08 (instead that should go to 106-8). I'm not sure I have thought out all the exceptions, though these are the most basic. I am mainly looking for the methodology to use, whether through find and replace or macros. I don't want to spend too much time trying to figure it out, because I'm not sure the return will be worth a lot of time invested. I know that by using wildcard search and replace I can do most of this. For instance, I could search for ([!0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9]) and replace with \1\2\3\4\\5\6, replacing something like 125126 to "12526. But that doesn't help me with all because I would still have to make adjustments for the above-mentioned exceptions. If automating using macros is the best choice, I would also like to figure out a way to double-check that changes were made correctly and there were no mistakes. So is it possible to write into the macro (if doing a macro) to copy all replacements (or all things being replaced) into a blank word document to be able to quickly scan all instances of replacements? Or to highlight all changes made in the document to be able to quickly pick up what was changed? Does this make sense? Can anyone help? Thanks. |
#4
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
This modification will leave 200-204 untouched, but will change 202-204 to
202-4 Dim numrange As Range, numrange1 As Range, numrange2 As Range Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="[0-9]{1,}-[0-9]{1,}", MatchWildcards:=True, _ Wrap:=wdFindStop, Forward:=True) = True Set numrange = Selection.Range Selection.Range.Collapse wdCollapseEnd Set numrange1 = numrange.Duplicate Set numrange2 = numrange.Duplicate numrange1.End = numrange1.Start + InStr(numrange1, "-") - 1 numrange2.Start = numrange2.Start + InStr(numrange2, "-") If Len(numrange1) = Len(numrange2) Then If Left(numrange1, 1) = Left(numrange2, 1) Then If Mid(numrange1, 2, 1) = Mid(numrange2, 2, 1) Then If Mid(numrange1, 2) "00" Then numrange = numrange1 & "-" & Mid(numrange2, 3) End If Else numrange = numrange1 & "-" & Mid(numrange2, 2) End If End If End If Loop End With What sort of notation do you want to show that the numbers have been changed? -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "JeremyC" wrote in message ... Thanks. Will that make exceptions for numbers such as 200-204, which should not be shortened, or for 202-204, which should be shortened to 202-4? Also, will that create notation to show which numbers were changed? I'm thinking that it won't work for these special circumstances, but perhaps I can figure out how to modify it do so. "JeremyC" wrote: I am using Word 2003, but if I can successfully figure out how to do this, I would also like to be able to do the same on Word 2004 for Mac. I am trying to figure out a way to automate replacing numbers in page ranges to match the Chicago Manual of Style. For instance, I need to change 149-167 to 149-67, but not 149-249 to 149-49 or not 106-108 to 106-08 (instead that should go to 106-8). I'm not sure I have thought out all the exceptions, though these are the most basic. I am mainly looking for the methodology to use, whether through find and replace or macros. I don't want to spend too much time trying to figure it out, because I'm not sure the return will be worth a lot of time invested. I know that by using wildcard search and replace I can do most of this. For instance, I could search for ([!0-9])([0-9])([0-9])([0-9])-([0-9])([0-9])([0-9]) and replace with \1\2\3\4\-\5\6, replacing something like " 125-126" to "125-26." But that doesn't help me with all because I would still have to make adjustments for the above-mentioned exceptions. If automating using macros is the best choice, I would also like to figure out a way to double-check that changes were made correctly and there were no mistakes. So is it possible to write into the macro (if doing a macro) to copy all replacements (or all things being replaced) into a blank word document to be able to quickly scan all instances of replacements? Or to highlight all changes made in the document to be able to quickly pick up what was changed? Does this make sense? Can anyone help? Thanks. |
#5
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
For the changes, ideally I would like to have the macro create a new document
and paste a copy of all the ranges replaced and what they were replaced with. That way I could just glance through the newly created document to double-check that nothing had gone amiss in the changes--that there weren't exceptions for that particular document. That may be too complex, in which case simply highlighting any replacement ranges or putting them in a different font color or size would be an acceptable alternative. "Doug Robbins - Word MVP" wrote: This modification will leave 200-204 untouched, but will change 202-204 to 202-4 Dim numrange As Range, numrange1 As Range, numrange2 As Range Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="[0-9]{1,}-[0-9]{1,}", MatchWildcards:=True, _ Wrap:=wdFindStop, Forward:=True) = True Set numrange = Selection.Range Selection.Range.Collapse wdCollapseEnd Set numrange1 = numrange.Duplicate Set numrange2 = numrange.Duplicate numrange1.End = numrange1.Start + InStr(numrange1, "-") - 1 numrange2.Start = numrange2.Start + InStr(numrange2, "-") If Len(numrange1) = Len(numrange2) Then If Left(numrange1, 1) = Left(numrange2, 1) Then If Mid(numrange1, 2, 1) = Mid(numrange2, 2, 1) Then If Mid(numrange1, 2) "00" Then numrange = numrange1 & "-" & Mid(numrange2, 3) End If Else numrange = numrange1 & "-" & Mid(numrange2, 2) End If End If End If Loop End With What sort of notation do you want to show that the numbers have been changed? -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "JeremyC" wrote in message ... Thanks. Will that make exceptions for numbers such as 200-204, which should not be shortened, or for 202-204, which should be shortened to 202-4? Also, will that create notation to show which numbers were changed? I'm thinking that it won't work for these special circumstances, but perhaps I can figure out how to modify it do so. "JeremyC" wrote: I am using Word 2003, but if I can successfully figure out how to do this, I would also like to be able to do the same on Word 2004 for Mac. I am trying to figure out a way to automate replacing numbers in page ranges to match the Chicago Manual of Style. For instance, I need to change 149-167 to 149-67, but not 149-249 to 149-49 or not 106-108 to 106-08 (instead that should go to 106-8). I'm not sure I have thought out all the exceptions, though these are the most basic. I am mainly looking for the methodology to use, whether through find and replace or macros. I don't want to spend too much time trying to figure it out, because I'm not sure the return will be worth a lot of time invested. I know that by using wildcard search and replace I can do most of this. For instance, I could search for ([!0-9])([0-9])([0-9])([0-9])-([0-9])([0-9])([0-9]) and replace with \1\2\3\4\-\5\6, replacing something like " 125-126" to "125-26." But that doesn't help me with all because I would still have to make adjustments for the above-mentioned exceptions. If automating using macros is the best choice, I would also like to figure out a way to double-check that changes were made correctly and there were no mistakes. So is it possible to write into the macro (if doing a macro) to copy all replacements (or all things being replaced) into a blank word document to be able to quickly scan all instances of replacements? Or to highlight all changes made in the document to be able to quickly pick up what was changed? Does this make sense? Can anyone help? Thanks. |
#6
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
How about saving the document before running the macro, run the macro and
then use the ToolsCompare and Merge Documents utility. Or, the following macro will create a separate document in which will be listed all of the changes: Sub A() Dim numrange As Range, numrange1 As Range, numrange2 As Range Dim source As Document, target As Document Set source = ActiveDocument Set target = Documents.Add source.Activate Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="[0-9]{1,}-[0-9]{1,}", MatchWildcards:=True, _ Wrap:=wdFindStop, Forward:=True) = True Set numrange = Selection.Range Selection.Range.Collapse wdCollapseEnd Set numrange1 = numrange.Duplicate Set numrange2 = numrange.Duplicate numrange1.End = numrange1.Start + InStr(numrange1, "-") - 1 numrange2.Start = numrange2.Start + InStr(numrange2, "-") If Len(numrange1) = Len(numrange2) Then If Left(numrange1, 1) = Left(numrange2, 1) Then If Mid(numrange1, 2, 1) = Mid(numrange2, 2, 1) Then If Mid(numrange1, 2) "00" Then target.Range.InsertAfter numrange numrange = numrange1 & "-" & Mid(numrange2, 3) target.Range.InsertAfter " was changed to " & numrange & vbCr End If Else target.Range.InsertAfter numrange numrange = numrange1 & "-" & Mid(numrange2, 2) target.Range.InsertAfter " was changed to " & numrange & vbCr End If End If End If Loop End With -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "JeremyC" wrote in message ... For the changes, ideally I would like to have the macro create a new document and paste a copy of all the ranges replaced and what they were replaced with. That way I could just glance through the newly created document to double-check that nothing had gone amiss in the changes--that there weren't exceptions for that particular document. That may be too complex, in which case simply highlighting any replacement ranges or putting them in a different font color or size would be an acceptable alternative. "Doug Robbins - Word MVP" wrote: This modification will leave 200-204 untouched, but will change 202-204 to 202-4 Dim numrange As Range, numrange1 As Range, numrange2 As Range Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="[0-9]{1,}-[0-9]{1,}", MatchWildcards:=True, _ Wrap:=wdFindStop, Forward:=True) = True Set numrange = Selection.Range Selection.Range.Collapse wdCollapseEnd Set numrange1 = numrange.Duplicate Set numrange2 = numrange.Duplicate numrange1.End = numrange1.Start + InStr(numrange1, "-") - 1 numrange2.Start = numrange2.Start + InStr(numrange2, "-") If Len(numrange1) = Len(numrange2) Then If Left(numrange1, 1) = Left(numrange2, 1) Then If Mid(numrange1, 2, 1) = Mid(numrange2, 2, 1) Then If Mid(numrange1, 2) "00" Then numrange = numrange1 & "-" & Mid(numrange2, 3) End If Else numrange = numrange1 & "-" & Mid(numrange2, 2) End If End If End If Loop End With What sort of notation do you want to show that the numbers have been changed? -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "JeremyC" wrote in message ... Thanks. Will that make exceptions for numbers such as 200-204, which should not be shortened, or for 202-204, which should be shortened to 202-4? Also, will that create notation to show which numbers were changed? I'm thinking that it won't work for these special circumstances, but perhaps I can figure out how to modify it do so. "JeremyC" wrote: I am using Word 2003, but if I can successfully figure out how to do this, I would also like to be able to do the same on Word 2004 for Mac. I am trying to figure out a way to automate replacing numbers in page ranges to match the Chicago Manual of Style. For instance, I need to change 149-167 to 149-67, but not 149-249 to 149-49 or not 106-108 to 106-08 (instead that should go to 106-8). I'm not sure I have thought out all the exceptions, though these are the most basic. I am mainly looking for the methodology to use, whether through find and replace or macros. I don't want to spend too much time trying to figure it out, because I'm not sure the return will be worth a lot of time invested. I know that by using wildcard search and replace I can do most of this. For instance, I could search for ([!0-9])([0-9])([0-9])([0-9])-([0-9])([0-9])([0-9]) and replace with \1\2\3\4\-\5\6, replacing something like " 125-126" to "125-26." But that doesn't help me with all because I would still have to make adjustments for the above-mentioned exceptions. If automating using macros is the best choice, I would also like to figure out a way to double-check that changes were made correctly and there were no mistakes. So is it possible to write into the macro (if doing a macro) to copy all replacements (or all things being replaced) into a blank word document to be able to quickly scan all instances of replacements? Or to highlight all changes made in the document to be able to quickly pick up what was changed? Does this make sense? Can anyone help? Thanks. |
#7
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Thank you so much. This should be most helpful. I'll run a few tests when I
get into work on Monday and let you know if I run into anything else I need help with. I had forgotten about the compare documents, so that might be a suitable alternative. "Doug Robbins - Word MVP" wrote: How about saving the document before running the macro, run the macro and then use the ToolsCompare and Merge Documents utility. Or, the following macro will create a separate document in which will be listed all of the changes: Sub A() Dim numrange As Range, numrange1 As Range, numrange2 As Range Dim source As Document, target As Document Set source = ActiveDocument Set target = Documents.Add source.Activate Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="[0-9]{1,}-[0-9]{1,}", MatchWildcards:=True, _ Wrap:=wdFindStop, Forward:=True) = True Set numrange = Selection.Range Selection.Range.Collapse wdCollapseEnd Set numrange1 = numrange.Duplicate Set numrange2 = numrange.Duplicate numrange1.End = numrange1.Start + InStr(numrange1, "-") - 1 numrange2.Start = numrange2.Start + InStr(numrange2, "-") If Len(numrange1) = Len(numrange2) Then If Left(numrange1, 1) = Left(numrange2, 1) Then If Mid(numrange1, 2, 1) = Mid(numrange2, 2, 1) Then If Mid(numrange1, 2) "00" Then target.Range.InsertAfter numrange numrange = numrange1 & "-" & Mid(numrange2, 3) target.Range.InsertAfter " was changed to " & numrange & vbCr End If Else target.Range.InsertAfter numrange numrange = numrange1 & "-" & Mid(numrange2, 2) target.Range.InsertAfter " was changed to " & numrange & vbCr End If End If End If Loop End With -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "JeremyC" wrote in message ... For the changes, ideally I would like to have the macro create a new document and paste a copy of all the ranges replaced and what they were replaced with. That way I could just glance through the newly created document to double-check that nothing had gone amiss in the changes--that there weren't exceptions for that particular document. That may be too complex, in which case simply highlighting any replacement ranges or putting them in a different font color or size would be an acceptable alternative. "Doug Robbins - Word MVP" wrote: This modification will leave 200-204 untouched, but will change 202-204 to 202-4 Dim numrange As Range, numrange1 As Range, numrange2 As Range Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="[0-9]{1,}-[0-9]{1,}", MatchWildcards:=True, _ Wrap:=wdFindStop, Forward:=True) = True Set numrange = Selection.Range Selection.Range.Collapse wdCollapseEnd Set numrange1 = numrange.Duplicate Set numrange2 = numrange.Duplicate numrange1.End = numrange1.Start + InStr(numrange1, "-") - 1 numrange2.Start = numrange2.Start + InStr(numrange2, "-") If Len(numrange1) = Len(numrange2) Then If Left(numrange1, 1) = Left(numrange2, 1) Then If Mid(numrange1, 2, 1) = Mid(numrange2, 2, 1) Then If Mid(numrange1, 2) "00" Then numrange = numrange1 & "-" & Mid(numrange2, 3) End If Else numrange = numrange1 & "-" & Mid(numrange2, 2) End If End If End If Loop End With What sort of notation do you want to show that the numbers have been changed? -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "JeremyC" wrote in message ... Thanks. Will that make exceptions for numbers such as 200-204, which should not be shortened, or for 202-204, which should be shortened to 202-4? Also, will that create notation to show which numbers were changed? I'm thinking that it won't work for these special circumstances, but perhaps I can figure out how to modify it do so. "JeremyC" wrote: I am using Word 2003, but if I can successfully figure out how to do this, I would also like to be able to do the same on Word 2004 for Mac. I am trying to figure out a way to automate replacing numbers in page ranges to match the Chicago Manual of Style. For instance, I need to change 149-167 to 149-67, but not 149-249 to 149-49 or not 106-108 to 106-08 (instead that should go to 106-8). I'm not sure I have thought out all the exceptions, though these are the most basic. I am mainly looking for the methodology to use, whether through find and replace or macros. I don't want to spend too much time trying to figure it out, because I'm not sure the return will be worth a lot of time invested. I know that by using wildcard search and replace I can do most of this. For instance, I could search for ([!0-9])([0-9])([0-9])([0-9])-([0-9])([0-9])([0-9]) and replace with \1\2\3\4\-\5\6, replacing something like " 125-126" to "125-26." But that doesn't help me with all because I would still have to make adjustments for the above-mentioned exceptions. If automating using macros is the best choice, I would also like to figure out a way to double-check that changes were made correctly and there were no mistakes. So is it possible to write into the macro (if doing a macro) to copy all replacements (or all things being replaced) into a blank word document to be able to quickly scan all instances of replacements? Or to highlight all changes made in the document to be able to quickly pick up what was changed? Does this make sense? Can anyone help? Thanks. |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find and Replace GREEK symbols in XP, 2K & 97 | Microsoft Word Help | |||
Find and Replace | New Users | |||
Find and Replace anomaly | Microsoft Word Help | |||
A "Ctrl + Page Down" doe a "find and replace", Why? | Microsoft Word Help | |||
find and replace symbols | New Users |