Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Hi
I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
I forgot to mention that i'm using Word 2003 SP3
-- lewisma "lewisma" wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
It is easy enough to run through a document and process a list of words or
phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Graham
Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks -- lewisma "Graham Mayor" wrote: It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
I copied and pasted your script into a new word macro, when i try to run it i
get the following error message. Compile Error: Expected End Sub Below is the script. Sub lewis() ' ' lewis Macro ' Macro created 18/08/2008 by MedQuist ' Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.Name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub End Sub Any ideas what i'm doing wrong here ? Your help is appreciated, thanks -- lewisma "lewisma" wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks -- lewisma "Graham Mayor" wrote: It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
If you can find suitable characters and substitute them in and the font they
are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
You should have pasted it *over* rather than into the macro.
http://www.gmayor.com/installing_macro.htm Remove the lines Sub lewis() ' ' lewis Macro ' Macro created 18/08/2008 by MedQuist ' and the final End Sub and you may prefer the second version, which is nearer your requirement. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I copied and pasted your script into a new word macro, when i try to run it i get the following error message. Compile Error: Expected End Sub Below is the script. Sub lewis() ' ' lewis Macro ' Macro created 18/08/2008 by MedQuist ' Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.Name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub End Sub Any ideas what i'm doing wrong here ? Your help is appreciated, thanks Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks -- lewisma "Graham Mayor" wrote: It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#8
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
After some playing about i now have it working, but when i run the macro
inside word it only changes the upper right and upper left phrases, it doesn't do anything for the bottom right and bottom left values, once that is working i guess i just need to figure out what to replace the phrases with, the font looks ok but i would really need the 2 lines for each phrase. Thanks -- lewisma "lewisma" wrote: I copied and pasted your script into a new word macro, when i try to run it i get the following error message. Compile Error: Expected End Sub Below is the script. Sub lewis() ' ' lewis Macro ' Macro created 18/08/2008 by MedQuist ' Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.Name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub End Sub Any ideas what i'm doing wrong here ? Your help is appreciated, thanks -- lewisma "lewisma" wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks -- lewisma "Graham Mayor" wrote: It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#9
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Graham
This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks -- lewisma "Graham Mayor" wrote: If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#10
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
http://www.gmayor.com/installing_macro.htm
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#11
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Sorry i didn't spot the link when i read your reply. OK i have tested this
and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#12
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Fantastic, i noticed on the script the wording was lower instead of bottom,
changed that and it looks great -- lewisma "lewisma" wrote: Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#13
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Glad you were able to get there in the end
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#14
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
This is fantastic, great job, one last thing if i wanted to add another
phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks -- lewisma "Graham Mayor" wrote: Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#15
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
The phrases and their replacements are configured in the two arrays
vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#16
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Graham
Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. -- lewisma "Graham Mayor" wrote: The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#17
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
You are welcome
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#18
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
I know i'm being a pain, this is what it looks like so far.
Extract ”˜ 5 Extract ”” 5 Extract ” 5 Extract ”Œ 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks -- lewisma "Graham Mayor" wrote: You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become |_ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#19
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Are you sure that's it?
Locate the line ..Replacement.Font.Size = 14 and add the following immediately after it Select Case i Case 0 .Replacement.Font.Position = -4 Case 1 .Replacement.Font.Position = -4 Case 2 .Replacement.Font.Position = 4 Case 3 .Replacement.Font.Position = 4 Case Else End Select This will process each item of the original four in the replacement array in order. Any others you have added to the end will not be affected. As for moving the two items closer together add a space in the find strings after both occurrences of 'left' i.e.. "upper left " and "bottom left " -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I know i'm being a pain, this is what it looks like so far. Extract ? 5 Extract ? 5 Extract ? 5 Extract ? 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become _ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance lewisma lewisma |
#20
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Works well, now looks like this
Extract ”˜ 5 Extract ””5 Extract ” 5 Extract ”Œ5 Just need to work out how to remove the space for lines 1 and 3 which is upper/bottom right -- lewisma "Graham Mayor" wrote: Are you sure that's it? Locate the line ..Replacement.Font.Size = 14 and add the following immediately after it Select Case i Case 0 .Replacement.Font.Position = -4 Case 1 .Replacement.Font.Position = -4 Case 2 .Replacement.Font.Position = 4 Case 3 .Replacement.Font.Position = 4 Case Else End Select This will process each item of the original four in the replacement array in order. Any others you have added to the end will not be affected. As for moving the two items closer together add a space in the find strings after both occurrences of 'left' i.e.. "upper left " and "bottom left " -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I know i'm being a pain, this is what it looks like so far. Extract ? 5 Extract ? 5 Extract ? 5 Extract ? 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and bottom left). These words will then need to be replaced by some kind of autoshape/symbol. Upper right would need to become _ Upper left would need to become _| Bottom right would need to become | with a line on the right hand side (at the top) Bottom left would need to become | with a line on the left hand side (at the top) The autoshape/symbol also needs to be active so the typist can type in a number of 1-8 in the box, this is a dental grid. I know how to record macros and i am happy finding and replacing words, but this is proving quite difficult to achieve. Is there any sort of vb script out there that will accomplish this, what is the best way to get the end result. I am very new to VB so my knowledge is very limited. Any help would be very much appreciated. Thanks in advance |
#21
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
If i add a space in the find string after right (upper and lower) it takes
away 1 space but there is still one space left to remove, i tried adding 2 spaces at the end of right, but that doesn't change the phrase at all. -- lewisma "lewisma" wrote: Works well, now looks like this Extract ”˜ 5 Extract ””5 Extract ” 5 Extract ”Œ5 Just need to work out how to remove the space for lines 1 and 3 which is upper/bottom right -- lewisma "Graham Mayor" wrote: Are you sure that's it? Locate the line ..Replacement.Font.Size = 14 and add the following immediately after it Select Case i Case 0 .Replacement.Font.Position = -4 Case 1 .Replacement.Font.Position = -4 Case 2 .Replacement.Font.Position = 4 Case 3 .Replacement.Font.Position = 4 Case Else End Select This will process each item of the original four in the replacement array in order. Any others you have added to the end will not be affected. As for moving the two items closer together add a space in the find strings after both occurrences of 'left' i.e.. "upper left " and "bottom left " -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I know i'm being a pain, this is what it looks like so far. Extract ? 5 Extract ? 5 Extract ? 5 Extract ? 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Hi I need to create a macro which will look through word documents. The macro will need to look for certain words which are (upper right, upper left, bottom right and |
#22
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
OK, i'm getting there with this, upper/lower left i think are fine. Here is
what upper/lower right currently look like. Extract ”˜5 (upper right) Extract ”5 (lower right) I need to move the symbols to the right of the number and take out the space between the two. Is there any adjustment i can make so i can make both lines slighlty longer ? -- lewisma "lewisma" wrote: If i add a space in the find string after right (upper and lower) it takes away 1 space but there is still one space left to remove, i tried adding 2 spaces at the end of right, but that doesn't change the phrase at all. -- lewisma "lewisma" wrote: Works well, now looks like this Extract ”˜ 5 Extract ””5 Extract ” 5 Extract ”Œ5 Just need to work out how to remove the space for lines 1 and 3 which is upper/bottom right -- lewisma "Graham Mayor" wrote: Are you sure that's it? Locate the line ..Replacement.Font.Size = 14 and add the following immediately after it Select Case i Case 0 .Replacement.Font.Position = -4 Case 1 .Replacement.Font.Position = -4 Case 2 .Replacement.Font.Position = 4 Case 3 .Replacement.Font.Position = 4 Case Else End Select This will process each item of the original four in the replacement array in order. Any others you have added to the end will not be affected. As for moving the two items closer together add a space in the find strings after both occurrences of 'left' i.e.. "upper left " and "bottom left " -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I know i'm being a pain, this is what it looks like so far. Extract ? 5 Extract ? 5 Extract ? 5 Extract ? 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org |
#23
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Let me get this clear - you now want
Extract 5? and Extract 5? but Extract ?5 and Extract ?5 plus, if possible, you want the horizontal part of the symbol longer? The first part should be easy enough, but it will require the wildcard option, which means that the searches will be case sensitive. So we will probably have to replace Upper with upper and Bottom with bottom first - or are they already the same case? The second part of the problem may not be so simple. It *may* be possible to combine two characters e.g ?? but then I have the feeling you will tell me that the horizontal is too long If you can find the combination of box characters that will work for you, I will try and find a way of combining them.... but it will have to wait until tomorrow at least. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: OK, i'm getting there with this, upper/lower left i think are fine. Here is what upper/lower right currently look like. Extract ?5 (upper right) Extract ?5 (lower right) I need to move the symbols to the right of the number and take out the space between the two. Is there any adjustment i can make so i can make both lines slighlty longer ? If i add a space in the find string after right (upper and lower) it takes away 1 space but there is still one space left to remove, i tried adding 2 spaces at the end of right, but that doesn't change the phrase at all. -- lewisma "lewisma" wrote: Works well, now looks like this Extract ? 5 Extract ?5 Extract ? 5 Extract ?5 Just need to work out how to remove the space for lines 1 and 3 which is upper/bottom right -- lewisma "Graham Mayor" wrote: Are you sure that's it? Locate the line ..Replacement.Font.Size = 14 and add the following immediately after it Select Case i Case 0 .Replacement.Font.Position = -4 Case 1 .Replacement.Font.Position = -4 Case 2 .Replacement.Font.Position = 4 Case 3 .Replacement.Font.Position = 4 Case Else End Select This will process each item of the original four in the replacement array in order. Any others you have added to the end will not be affected. As for moving the two items closer together add a space in the find strings after both occurrences of 'left' i.e.. "upper left " and "bottom left " -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I know i'm being a pain, this is what it looks like so far. Extract ? 5 Extract ? 5 Extract ? 5 Extract ? 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this make the end result a little easier now ? Look forward to your comments, thanks It is easy enough to run through a document and process a list of words or phrases, but the problem here is the autoshape and more particularly your requirement to have a shape that you can write in. The logical shape would be a table cell, to which you could apply borders to produce the four shapes and type in the space, but you cannot intersperse table cells with text - each cell would have to be on its own line. Text boxes etc are out because you cannot format the edges of the box individually. You could use (say) the characters 195/196 199/200 from the Wingdings font, which would provide suitably adventurous shapes, but you wouldn't be able to type in the spaces - only alongside. To do that - Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper right", "upper left", _ "lower right", "lower left") vReplText = Array(Chr(200), Chr(199), Chr(196), Chr(195)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Wingdings" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org |
#24
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
I am really sorry to be a nuisance, the person that requires this is a little
picky, i did work out the i can make the symbols slightly bigger by increasing the font size. So for now what i need to do is the first option which is to move the symbol to the right of the number, this is only needed for upper/lower right. Extract ”˜5 (upper right) needs to be 5 then the symbol Extract ”5 (lower right) needs to be 5 then the symbol If possible no spaces between the number and the symbol, i can add a space if i need to. -- lewisma "Graham Mayor" wrote: Let me get this clear - you now want Extract 5? and Extract 5? but Extract ?5 and Extract ?5 plus, if possible, you want the horizontal part of the symbol longer? The first part should be easy enough, but it will require the wildcard option, which means that the searches will be case sensitive. So we will probably have to replace Upper with upper and Bottom with bottom first - or are they already the same case? The second part of the problem may not be so simple. It *may* be possible to combine two characters e.g ?? but then I have the feeling you will tell me that the horizontal is too long If you can find the combination of box characters that will work for you, I will try and find a way of combining them.... but it will have to wait until tomorrow at least. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: OK, i'm getting there with this, upper/lower left i think are fine. Here is what upper/lower right currently look like. Extract ?5 (upper right) Extract ?5 (lower right) I need to move the symbols to the right of the number and take out the space between the two. Is there any adjustment i can make so i can make both lines slighlty longer ? If i add a space in the find string after right (upper and lower) it takes away 1 space but there is still one space left to remove, i tried adding 2 spaces at the end of right, but that doesn't change the phrase at all. -- lewisma "lewisma" wrote: Works well, now looks like this Extract ? 5 Extract ?5 Extract ? 5 Extract ?5 Just need to work out how to remove the space for lines 1 and 3 which is upper/bottom right -- lewisma "Graham Mayor" wrote: Are you sure that's it? Locate the line ..Replacement.Font.Size = 14 and add the following immediately after it Select Case i Case 0 .Replacement.Font.Position = -4 Case 1 .Replacement.Font.Position = -4 Case 2 .Replacement.Font.Position = 4 Case 3 .Replacement.Font.Position = 4 Case Else End Select This will process each item of the original four in the replacement array in order. Any others you have added to the end will not be affected. As for moving the two items closer together add a space in the find strings after both occurrences of 'left' i.e.. "upper left " and "bottom left " -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I know i'm being a pain, this is what it looks like so far. Extract ? 5 Extract ? 5 Extract ? 5 Extract ? 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this |
#25
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
Your picky dentist isn't paying me for my time to keep recreating this code,
because he keeps changing his mind! How much of his expertise does he/she offer for free? This took a bit of head scratching and some abortive attempts to do it more simply, but it requires modifications to large sections of the code As you want the numbers transposed, the simplest way is to do that first. I have assumed that all the 'uppers' and 'bottoms' are in lower case as wildcard searches are case sensitive. I do not know what you did with the + sign so I have omitted it. Be careful of the array order, and the consequent case statement numbering if you add extra search sequences. I have broken the Findtext array into three lines to avoid problems with the e-mail system I have changed the font size for the symbols to 16 and moved the font sizing to the case statements. There are no spaces between the symbols and the numbers. The spacing is attributable to the internal spacing in the font. Short of creating your own font (which is possible, but time consuming) there is nothing you can do about the spacing between the numbers and the symbols. Note that the Case statements refer to the order of the items in the array starting with 0. Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("(upper right) ([0-9]{1,})", _ "(bottom right) ([0-9]{1,})", "upper left ", _ "upper right", "bottom left ", "bottom right ") vReplText = Array("\2\1", "\2\1", ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" Select Case i Case 2 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 3 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 4 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case 5 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case Else End Select .Execute Replace:=wdReplaceAll Next i End With End With End Sub lewisma wrote: I am really sorry to be a nuisance, the person that requires this is a little picky, i did work out the i can make the symbols slightly bigger by increasing the font size. So for now what i need to do is the first option which is to move the symbol to the right of the number, this is only needed for upper/lower right. Extract ?5 (upper right) needs to be 5 then the symbol Extract ?5 (lower right) needs to be 5 then the symbol If possible no spaces between the number and the symbol, i can add a space if i need to. Let me get this clear - you now want Extract 5? and Extract 5? but Extract ?5 and Extract ?5 plus, if possible, you want the horizontal part of the symbol longer? The first part should be easy enough, but it will require the wildcard option, which means that the searches will be case sensitive. So we will probably have to replace Upper with upper and Bottom with bottom first - or are they already the same case? The second part of the problem may not be so simple. It *may* be possible to combine two characters e.g ?? but then I have the feeling you will tell me that the horizontal is too long If you can find the combination of box characters that will work for you, I will try and find a way of combining them.... but it will have to wait until tomorrow at least. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: OK, i'm getting there with this, upper/lower left i think are fine. Here is what upper/lower right currently look like. Extract ?5 (upper right) Extract ?5 (lower right) I need to move the symbols to the right of the number and take out the space between the two. Is there any adjustment i can make so i can make both lines slighlty longer ? If i add a space in the find string after right (upper and lower) it takes away 1 space but there is still one space left to remove, i tried adding 2 spaces at the end of right, but that doesn't change the phrase at all. -- lewisma "lewisma" wrote: Works well, now looks like this Extract ? 5 Extract ?5 Extract ? 5 Extract ?5 Just need to work out how to remove the space for lines 1 and 3 which is upper/bottom right -- lewisma "Graham Mayor" wrote: Are you sure that's it? Locate the line ..Replacement.Font.Size = 14 and add the following immediately after it Select Case i Case 0 .Replacement.Font.Position = -4 Case 1 .Replacement.Font.Position = -4 Case 2 .Replacement.Font.Position = 4 Case 3 .Replacement.Font.Position = 4 Case Else End Select This will process each item of the original four in the replacement array in order. Any others you have added to the end will not be affected. As for moving the two items closer together add a space in the find strings after both occurrences of 'left' i.e.. "upper left " and "bottom left " -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I know i'm being a pain, this is what it looks like so far. Extract ? 5 Extract ? 5 Extract ? 5 Extract ? 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Fantastic, i noticed on the script the wording was lower instead of bottom, changed that and it looks great Sorry i didn't spot the link when i read your reply. OK i have tested this and it seems to work really well, how do i get the script to change for bottom right/left. It only changes the upper phrases but this is definatly looking good, i really appreciate your help with this -- lewisma "Graham Mayor" wrote: http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham This is fantastic, i will give it a try, what's the best way to get the script into a macro, before i just went into Word/Macro and Create Macro, named it and just pasted in the script, should i be doing it that way or is there another way to do this ? Thanks If you can find suitable characters and substitute them in and the font they are derived from in the macro I posted, it will do just that.. Digging around in Unicode fonts for some suitable shape I came up with the following which uses box drawing shapes from the Arial Unicode font, which is a fairly standard font that you will have. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" .Replacement.Font.Size = 14 .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Many thanks for your quick response. I have just been told that the shape does not need to have anything typed into it now. So all that needs to be done is for the phrases to be replaced by the shape. Does this |
#26
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
I'm really sorry, i keep getting a compile error when i try to run this.
Compile error: Invalid outside procedure The Macro is listed below. Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("(upper right) ([0-9]{1,})", _ "(bottom right) ([0-9]{1,})", "upper left ", _ "upper right", "bottom left ", "bottom right ") vReplText = Array("\2\1", "\2\1", ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.Name = "Arial" Select Case i Case 2 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 3 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 4 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case 5 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case Else End Select .Execute Replace:=wdReplaceAll Next i End With End With End Sub Not sure what i'm doing wrong here. -- lewisma "Graham Mayor" wrote: Your picky dentist isn't paying me for my time to keep recreating this code, because he keeps changing his mind! How much of his expertise does he/she offer for free? This took a bit of head scratching and some abortive attempts to do it more simply, but it requires modifications to large sections of the code As you want the numbers transposed, the simplest way is to do that first. I have assumed that all the 'uppers' and 'bottoms' are in lower case as wildcard searches are case sensitive. I do not know what you did with the + sign so I have omitted it. Be careful of the array order, and the consequent case statement numbering if you add extra search sequences. I have broken the Findtext array into three lines to avoid problems with the e-mail system I have changed the font size for the symbols to 16 and moved the font sizing to the case statements. There are no spaces between the symbols and the numbers. The spacing is attributable to the internal spacing in the font. Short of creating your own font (which is possible, but time consuming) there is nothing you can do about the spacing between the numbers and the symbols. Note that the Case statements refer to the order of the items in the array starting with 0. Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("(upper right) ([0-9]{1,})", _ "(bottom right) ([0-9]{1,})", "upper left ", _ "upper right", "bottom left ", "bottom right ") vReplText = Array("\2\1", "\2\1", ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" Select Case i Case 2 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 3 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 4 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case 5 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case Else End Select .Execute Replace:=wdReplaceAll Next i End With End With End Sub lewisma wrote: I am really sorry to be a nuisance, the person that requires this is a little picky, i did work out the i can make the symbols slightly bigger by increasing the font size. So for now what i need to do is the first option which is to move the symbol to the right of the number, this is only needed for upper/lower right. Extract ?5 (upper right) needs to be 5 then the symbol Extract ?5 (lower right) needs to be 5 then the symbol If possible no spaces between the number and the symbol, i can add a space if i need to. Let me get this clear - you now want Extract 5? and Extract 5? but Extract ?5 and Extract ?5 plus, if possible, you want the horizontal part of the symbol longer? The first part should be easy enough, but it will require the wildcard option, which means that the searches will be case sensitive. So we will probably have to replace Upper with upper and Bottom with bottom first - or are they already the same case? The second part of the problem may not be so simple. It *may* be possible to combine two characters e.g ?? but then I have the feeling you will tell me that the horizontal is too long If you can find the combination of box characters that will work for you, I will try and find a way of combining them.... but it will have to wait until tomorrow at least. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: OK, i'm getting there with this, upper/lower left i think are fine. Here is what upper/lower right currently look like. Extract ?5 (upper right) Extract ?5 (lower right) I need to move the symbols to the right of the number and take out the space between the two. Is there any adjustment i can make so i can make both lines slighlty longer ? If i add a space in the find string after right (upper and lower) it takes away 1 space but there is still one space left to remove, i tried adding 2 spaces at the end of right, but that doesn't change the phrase at all. -- lewisma "lewisma" wrote: Works well, now looks like this Extract ? 5 Extract ?5 Extract ? 5 Extract ?5 Just need to work out how to remove the space for lines 1 and 3 which is upper/bottom right -- lewisma "Graham Mayor" wrote: Are you sure that's it? Locate the line ..Replacement.Font.Size = 14 and add the following immediately after it Select Case i Case 0 .Replacement.Font.Position = -4 Case 1 .Replacement.Font.Position = -4 Case 2 .Replacement.Font.Position = 4 Case 3 .Replacement.Font.Position = 4 Case Else End Select This will process each item of the original four in the replacement array in order. Any others you have added to the end will not be affected. As for moving the two items closer together add a space in the find strings after both occurrences of 'left' i.e.. "upper left " and "bottom left " -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I know i'm being a pain, this is what it looks like so far. Extract ? 5 Extract ? 5 Extract ? 5 Extract ? 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org |
#27
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
We'll get this right yet
Which line is highlighted when you get the error? Did you by any chance leave the extra End Sub line in place when you pasted the code into your macro? There is a broken line attributable to the e-mail editor line length. Paste the foillowing in place of yoir original macro and try again. It works fine here. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("(upper right) ([0-9]{1,})", _ "(bottom right) ([0-9]{1,})", "upper left ", _ "upper right", "bottom left ", "bottom right ") vReplText = Array("\2\1", "\2\1", ChrW(9496), _ ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" Select Case i Case 2 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 3 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 4 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case 5 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case Else End Select .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I'm really sorry, i keep getting a compile error when i try to run this. Compile error: Invalid outside procedure The Macro is listed below. Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("(upper right) ([0-9]{1,})", _ "(bottom right) ([0-9]{1,})", "upper left ", _ "upper right", "bottom left ", "bottom right ") vReplText = Array("\2\1", "\2\1", ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.Name = "Arial" Select Case i Case 2 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 3 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 4 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case 5 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case Else End Select .Execute Replace:=wdReplaceAll Next i End With End With End Sub Not sure what i'm doing wrong here. Your picky dentist isn't paying me for my time to keep recreating this code, because he keeps changing his mind! How much of his expertise does he/she offer for free? This took a bit of head scratching and some abortive attempts to do it more simply, but it requires modifications to large sections of the code As you want the numbers transposed, the simplest way is to do that first. I have assumed that all the 'uppers' and 'bottoms' are in lower case as wildcard searches are case sensitive. I do not know what you did with the + sign so I have omitted it. Be careful of the array order, and the consequent case statement numbering if you add extra search sequences. I have broken the Findtext array into three lines to avoid problems with the e-mail system I have changed the font size for the symbols to 16 and moved the font sizing to the case statements. There are no spaces between the symbols and the numbers. The spacing is attributable to the internal spacing in the font. Short of creating your own font (which is possible, but time consuming) there is nothing you can do about the spacing between the numbers and the symbols. Note that the Case statements refer to the order of the items in the array starting with 0. Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("(upper right) ([0-9]{1,})", _ "(bottom right) ([0-9]{1,})", "upper left ", _ "upper right", "bottom left ", "bottom right ") vReplText = Array("\2\1", "\2\1", ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) .Replacement.Font.name = "Arial" Select Case i Case 2 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 3 .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 4 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case 5 .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case Else End Select .Execute Replace:=wdReplaceAll Next i End With End With End Sub lewisma wrote: I am really sorry to be a nuisance, the person that requires this is a little picky, i did work out the i can make the symbols slightly bigger by increasing the font size. So for now what i need to do is the first option which is to move the symbol to the right of the number, this is only needed for upper/lower right. Extract ?5 (upper right) needs to be 5 then the symbol Extract ?5 (lower right) needs to be 5 then the symbol If possible no spaces between the number and the symbol, i can add a space if i need to. Let me get this clear - you now want Extract 5? and Extract 5? but Extract ?5 and Extract ?5 plus, if possible, you want the horizontal part of the symbol longer? The first part should be easy enough, but it will require the wildcard option, which means that the searches will be case sensitive. So we will probably have to replace Upper with upper and Bottom with bottom first - or are they already the same case? The second part of the problem may not be so simple. It *may* be possible to combine two characters e.g ?? but then I have the feeling you will tell me that the horizontal is too long If you can find the combination of box characters that will work for you, I will try and find a way of combining them.... but it will have to wait until tomorrow at least. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: OK, i'm getting there with this, upper/lower left i think are fine. Here is what upper/lower right currently look like. Extract ?5 (upper right) Extract ?5 (lower right) I need to move the symbols to the right of the number and take out the space between the two. Is there any adjustment i can make so i can make both lines slighlty longer ? If i add a space in the find string after right (upper and lower) it takes away 1 space but there is still one space left to remove, i tried adding 2 spaces at the end of right, but that doesn't change the phrase at all. -- lewisma "lewisma" wrote: Works well, now looks like this Extract ? 5 Extract ?5 Extract ? 5 Extract ?5 Just need to work out how to remove the space for lines 1 and 3 which is upper/bottom right -- lewisma "Graham Mayor" wrote: Are you sure that's it? Locate the line ..Replacement.Font.Size = 14 and add the following immediately after it Select Case i Case 0 .Replacement.Font.Position = -4 Case 1 .Replacement.Font.Position = -4 Case 2 .Replacement.Font.Position = 4 Case 3 .Replacement.Font.Position = 4 Case Else End Select This will process each item of the original four in the replacement array in order. Any others you have added to the end will not be affected. As for moving the two items closer together add a space in the find strings after both occurrences of 'left' i.e.. "upper left " and "bottom left " -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: I know i'm being a pain, this is what it looks like so far. Extract ? 5 Extract ? 5 Extract ? 5 Extract ? 5 Is it possible to close the spaces so there is not as much of a gap between the symbol and the number, the top 2 phrases are upper so they that symbol would need to go down 1 line and slighlty across and the bottom 2 are for the lower phrase, looks like that needs to go up 1 line and slighlty across. I want to see of i can align them a bit more accurately. Thanks You are welcome -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: Graham Fantastic, your a genius, works like a charm, many many thanks for your help with this, it would have taken me forever to figure this all out. The phrases and their replacements are configured in the two arrays vFindText = Array("upper left", "upper right", "lower left", "lower right") vReplText = Array(ChrW(9496), ChrW(9492), ChrW(9488), ChrW(9484)) The order in the first list corresponds with the order in the second list, with each item separated by a comma. You can use plain text or character strings. If you use the former you would surround the text with straight quotes as shown in the first line. In the second line I have used the unicode numbers for the characters in the extended character set of the Arial font. If you are looking up suitable characters use the Insert Symbol command and browse through those available. Character 265B might be suitable. Having chosen the character note the HEX number - here 265B, which you need to convert to its decimal equivalent. The simplest way to do that is to use the Windows Calculator in its Scientific view. With the Hex button checked, type in 265B, then click the Dec button and if you have done it correctly you would get 9819. So for that character you would enter ChrW(9819). If you want a simple + sign then add "+" to the replace string instead - or if you prefer ChrW(43) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lewisma wrote: This is fantastic, great job, one last thing if i wanted to add another phrase in which would be something like everything or all (this would be for upper right/left and lower right/left) i think they would require the + symbol for this to allow for everything, how do i add that into the current working script Many thanks Glad you were able to get there in the end -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org |
#28
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
While checking I noticed another minor issue relating to the font in the
transposed numbers. The following will fix that too. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("(upper right) ([0-9]{1,})", _ "(bottom right) ([0-9]{1,})", "upper left ", _ "upper right", "bottom left ", "bottom right ") vReplText = Array("\2\1", "\2\1", ChrW(9496), _ ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) Select Case i Case 2 .Replacement.Font.name = "Arial" .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 3 .Replacement.Font.name = "Arial" .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 4 .Replacement.Font.name = "Arial" .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case 5 .Replacement.Font.name = "Arial" .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case Else End Select .Execute Replace:=wdReplaceAll Next i End With End With End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org |
#29
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Creating a Macro
This macro will drive me crazy yet
The arrays now introduce an extra space in two of the substitutions ..... aaaaagh! Use vFindText = Array("(upper right) ([0-9]{1,})", _ "(bottom right) ([0-9]{1,})", "upper left ", _ "upper right", "bottom left ", "bottom right") vReplText = Array("\2\1", "\2\1", ChrW(9496), _ ChrW(9492), ChrW(9488), ChrW(9484)) instead -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: While checking I noticed another minor issue relating to the font in the transposed numbers. The following will fix that too. Sub ReplaceList() Dim vFindText As Variant Dim vReplText As Variant Dim i As Long vFindText = Array("(upper right) ([0-9]{1,})", _ "(bottom right) ([0-9]{1,})", "upper left ", _ "upper right", "bottom left ", "bottom right ") vReplText = Array("\2\1", "\2\1", ChrW(9496), _ ChrW(9492), ChrW(9488), ChrW(9484)) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWholeWord = True .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Format = True .MatchCase = False For i = LBound(vFindText) To UBound(vFindText) .Text = vFindText(i) .Replacement.Text = vReplText(i) Select Case i Case 2 .Replacement.Font.name = "Arial" .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 3 .Replacement.Font.name = "Arial" .Replacement.Font.Size = 16 .Replacement.Font.Position = -4 Case 4 .Replacement.Font.name = "Arial" .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case 5 .Replacement.Font.name = "Arial" .Replacement.Font.Size = 16 .Replacement.Font.Position = 4 Case Else End Select .Execute Replace:=wdReplaceAll Next i End With End With End Sub |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Creating a custom Macro in 07 | Microsoft Word Help | |||
creating a macro | Microsoft Word Help | |||
Creating a macro | Page Layout | |||
creating a macro | New Users | |||
I need help creating a macro to use for a big network. | Microsoft Word Help |