Reply
 
Thread Tools Display Modes
  #1   Report Post  
Jedumi Jedumi is offline
Junior Member
 
Location: Johannesburg
Posts: 0
Default Find, but Replace with mixed attributes

I'm getting close in my research, but can't yet find a way to:

Find for example:

(c.1949)

and Replace with

(c.1949)

Where the 'c' only is italicized.

Once I get the code for this, I'll be able to adapt to other and more complex scenarios, I hope.
  #2   Report Post  
Jedumi Jedumi is offline
Junior Member
 
Location: Johannesburg
Posts: 0
Default

mmmm...

That didn't quite come out the way I wanted it. It was supposed to only show the 'c' in italics and the rest in not-italics.

Quote:
Originally Posted by Jedumi View Post
I'm getting close in my research, but can't yet find a way to:

Find for example:

(c.1949)

and Replace with

(c.1949)

Where the 'c' only is italicized.

Once I get the code for this, I'll be able to adapt to other and more complex scenarios, I hope.
  #3   Report Post  
Jedumi Jedumi is offline
Junior Member
 
Location: Johannesburg
Posts: 0
Default

OK, Found it! With many thanks to Graham Mayor...

I amended some code from his website:

Sub DateAbbrevItalicize()

With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:="(c.", _
MatchWildcards:=False, _
Wrap:=wdFindStop, _
Forward:=True) = True
'Do what you want with the found text (Selection.Range)
'In this case format the second character as subscripted
Selection.Range.Characters(2).Font.Italic = True
' Selection.Range.Characters(2).Font.Subscript = True
Loop 'and look for the next match
End With
End With

End Sub


Quote:
Originally Posted by Jedumi View Post
mmmm...

That didn't quite come out the way I wanted it. It was supposed to only show the 'c' in italics and the rest in not-italics.
  #4   Report Post  
Jedumi Jedumi is offline
Junior Member
 
Location: Johannesburg
Posts: 0
Thumbs up

OK, I found what I was looking for - with many thanks to Graham Mayor.

I have amended some code on his website and done the following:

Sub DateAbbrevItalicize()

With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:="(c.", _
MatchWildcards:=False, _
Wrap:=wdFindStop, _
Forward:=True) = True
'Do what you want with the found text (Selection.Range)
'In this case format the second character as italicized
Selection.Range.Characters(2).Font.Italic = True
Loop 'and look for the next match
End With
End With

End Sub


Quote:
Originally Posted by Jedumi View Post
mmmm...

That didn't quite come out the way I wanted it. It was supposed to only show the 'c' in italics and the rest in not-italics.
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Peter T. Daniels Peter T. Daniels is offline
external usenet poster
 
Posts: 3,215
Default Find, but Replace with mixed attributes

You could Find the string

(c.

and Replace it with the contents of the Clipboard

^c

after you put on the clipboard

(c.

with the c italicized. (Assuming the dash at the end isn't part of
what you want inserted. If it is, then simply search for a longer
string and replace it with a longer string.)


On Mar 14, 2:36*am, Jedumi
wrote:
I'm getting close in my research, but can't yet find a way to:

Find for example:

(c.1949)

and Replace with

(-c-.1949)--

Where the 'c' only is italicized.

Once I get the code for this, I'll be able to adapt to other and more
complex scenarios, I hope.



  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Paul Paul is offline
external usenet poster
 
Posts: 3
Default Find, but Replace with mixed attributes

On 2012-03-14, Jedumi wrote:

I'm getting close in my research, but can't yet find a way to:
Find for example:
(c.1949)
and Replace with
(-c-.1949)--
Where the 'c' only is italicized.
Once I get the code for this, I'll be able to adapt to other and more
complex scenarios, I hope.


You can turn on wildcards and use some more advanced regular expression
operators in both the Find What and Replace With fields.

For example in the Find What, you could use \((c). ([0-9]{4})\)
and in the Replace With field, you could use (-\1-.\2)--

That would perform the desired replacement in your example.

Here's a breakdown of what the expressions are doing:

\( is the opening paren. It must be preceded by a backslash so that the
Find-Replace tool sees it as a literal paren.

(c) captures the 'c' so that it can be referenced in the Replace With
expression

([0-9]{4}) Searches for any single digit in the class '0-9' that is
repeated 4 times. This grouping is also captured with parentheses so
that it can be referenced in the Replace With expression.

\) Ssearches for a literal closing paren.

In the Replace With expression:

( inserts a parenthesis

\1 inserts the first captured group (the '(c)' in the Find What
expression).

\2 inserts the second captured group (the '([0-9]{4})' in the Find What
expression).

For more info, look he
http://www.bokorlang.com/journal/15msw.htm

and he
https://office.microsoft.com/en-us/w...102350661.aspx






--
Best of all is never to have been born. Second best is to die soon.
  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Peter T. Daniels Peter T. Daniels is offline
external usenet poster
 
Posts: 3,215
Default Find, but Replace with mixed attributes

On Mar 14, 12:20*pm, Paul wrote:
On 2012-03-14, Jedumi wrote:

I'm getting close in my research, but can't yet find a way to:
Find for example:
(c.1949)
and Replace with
(-c-.1949)--
Where the 'c' only is italicized.
Once I get the code for this, I'll be able to adapt to other and more
complex scenarios, I hope.


You can turn on wildcards and use some more advanced regular expression
operators in both the Find What and Replace With fields.

For example in the Find What, you could use \((c). ([0-9]{4})\)
and in the Replace With field, you could use (-\1-.\2)--


He doesn't want hyphens around the c, he wants the c to be italic.
(The dash after the date was probably part of the metadiscussion, not
what he wants to insert -- what function would it perform?)

That would perform the desired replacement in your example.

Here's a breakdown of what the expressions are doing:

\( is the opening paren. It must be preceded by a backslash so that the
Find-Replace tool sees it as a literal paren.

(c) captures the 'c' so that it can be referenced in the Replace With
expression

([0-9]{4}) Searches for any single digit in the class '0-9' that is
repeated 4 times. This grouping is also captured with parentheses so
that it can be referenced in the Replace With expression.

\) Ssearches for a literal closing paren.

In the Replace With expression:

( inserts a parenthesis

\1 inserts the first captured group (the '(c)' in the Find What
expression).

\2 inserts the second captured group (the '([0-9]{4})' in the Find What
expression).

For more info, look hehttp://www.bokorlang.com/journal/15msw.htm

and hehttps://office.microsoft.com/en-us/w...eplace-text-by...

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find+Replace Dialog Box, Replace with Format problem Kathy Microsoft Word Help 3 February 1st 08 04:26 AM
Find multiple characters in one find using MSword find/replace Cliff Microsoft Word Help 2 October 29th 06 07:48 PM
Using find and replace or macros to replace page ranges JeremyC Microsoft Word Help 7 February 13th 06 09:20 PM
Find/ Replace is auto-capping the words I want to replace with Graham Mayor Microsoft Word Help 8 January 27th 06 01:39 AM
How can I create a macro to find and replace text attributes? pubgal23 Microsoft Word Help 3 September 8th 05 06:09 AM


All times are GMT +1. The time now is 12:07 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"