Group:  Microsoft Word ยป microsoft.public.word.vba.beginners
Thread: How to format a string in a variable

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

How to format a string in a variable
Guillermo <guillermo[ at ]deletethislopez-anglada.com> 01.03.2006 21:43:22

Hello everyone,

I'm sorry if I'm asking something obvious, but I'm at lost with this.

In the line

..Text = b & "[[" & a & " (md)]]"

below I'd like to apply different formats to b, "[[" and " (md)]]" and b (i. e.
different font colors, etc).

Is it possible to format this text before adding it to the document (before the
replace command is executed)?

Thanks,

Guillermo


Here's a snippet of my code:

<code>

Sub MergeTerms(a As Variant, b As Variant)

Dim rango1 As Range

Set rango1 = Documents(TargetDoc).Range

With rango1.Find
.ClearFormatting
.Font.Hidden = False
.Text = a

With .Replacement
If FormatSp = "AllUpper" Then
'StrConv permite transformar una cadena

.Text = StrConv(b, vbUpperCase) & "[[" & a & " (gr)]]"
.Font.Underline = wdUnderlineDouble
.Font.UnderlineColor = wdColorBlue
ElseIf FormatSp = "AllBold" Then

.Text = b & "[[" & a & " (md)]]"
.Font.Bold = True
.Font.Underline = wdUnderlineDouble
.Font.UnderlineColor = wdColorBlue
Else
.Text = b & "[[" & a & "]]"
.Font.Underline = wdUnderlineDouble
.Font.UnderlineColor = wdColorBlue

End If

End With
.Execute Format:=True, Replace:=wdReplaceAll
End With


With Documents(TargetDoc).Range.Find
.ClearFormatting
.Font.Hidden = False
.Text = "\[\[" & "*" & "\]\]"
With .Replacement
.Text = "^&"
With .Font
.Hidden = True
.Color = wdColorBrown
.Underline = wdUnderlineNone
End With

End With
.Execute Format:=True, Replace:=wdReplaceAll, MatchWildcards:=True
End With


End Sub

Sub deleteunderline()
Dim rango1 As Range

Set rango1 = ActiveDocument.Range

With rango1.Find
.Format = True
'.MatchWildcards = True
'.text = "\[\[*\]\]"
.Font.Underline = wdUnderlineDouble
.Font.UnderlineColor = wdColorBlue

With .Replacement
.Text = "^&"
'.Font.Color = wdColorDarkRed
.Font.Underline = wdUnderlineNone
'.Font.Hidden = True
End With

.Execute Replace:=wdReplaceAll
End With

End Sub

<end of code>
Re: How to format a string in a variable
Jay Freedman <jay.freedman[ at ]verizon.net> 02.03.2006 03:47:43
Hi Guillermo,

No, it is not possible. You must insert text into a document and then
format it. You can insert the whole string in the document and then
use the Selection or a Range object to select each part in turn and
format it. Alternatively, you can insert each part of the string,
format that part, then insert the next part, format that, etc.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Wed, 01 Mar 2006 22:43:22 +0100, Guillermo
<guillermo[ at ]deletethislopez-anglada.com> wrote:

[Quoted Text]
>
>Hello everyone,
>
>I'm sorry if I'm asking something obvious, but I'm at lost with this.
>
>In the line
>
>.Text = b & "[[" & a & " (md)]]"
>
>below I'd like to apply different formats to b, "[[" and " (md)]]" and b (i. e.
>different font colors, etc).
>
>Is it possible to format this text before adding it to the document (before the
>replace command is executed)?
>
>Thanks,
>
>Guillermo
>

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net