New text adopt new font?

R

Rick Charnes

In Word 2003, I'm copying selected text into a variable with:

myvar = Selection

I then want to insert this text into another part of my document that
uses a different font, but I'd like the newly-inserted text to take on
this different font. If I just use "Selection.TypeText()", it retains
its original font. Is there an easy way to do this? Thanks.
 
D

Doug Robbins - Word MVP

Use a DOCVARIABLE field with a \* charformat switch. Then if you apply the
desired formatting to the D of DOCVARIABLE, that information contained in
the variable will be displayed in that font.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Rick Charnes

Thanks, but this is unfamiliar territory. I'm not familiar with
document variables, so I just looked it up in Help and I *think* I get
it. So I need to make these vars document variables? I'm not sure what
you mean when you refer to the /* charformat switch, or the D of
DOCVARIABLE. Thanks for any further clarification.
 
D

Doug Robbins - Word MVP

The field construction would be of the form

{ DOCVARIABLE myvar \* charformat }

and you would apply the desired formatting to the D of DOCVARIABLE

You load the information into the variable by using

With ActiveDocument
.Variables("myvar").Value = Selection.Text
.Fields.Update
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Bear

Rick:

This works fine for me, re adopting the target site's formatting:

Sub x()
'
' x Macro
' Macro recorded 5/7/2007 by David Chinell
'
Dim myVar As String

myVar = Selection

Selection.TypeText Text:=myVar

End Sub

Maybe dimming myVar as a string helps? I also considered that Selection
represents EVERYTHING in your selection, induding formatting, and tried

myVar = Selection.Text

To limit filling myVar to just the text of the selection.

It was hard to tell if this would make any difference, as it was already
working the first way.

Bear
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top