Control Font on paste

D

downwitch

Hi, very familiar with Access & Excel VBA and am trying to get up to
speed on Word's object model...

Here's the deal: users create new documents from a given template.
Often they're cutting & pasting from other sources, of course, and if
the font/size is outside the Normal style, the destination document
doesn't get it, keeps the source doc formatting--I want to force the
same font/size on all text, period.

I can do a find/replace on wildcard text and set the font/size that
way, but it doesn't seem very elegant.

1. Is there a way to loop through/search for all text *not* in a
font/size and replace it?

2. Apparently I can't search on styles or paste without formatting
because markup like bold & italic would also be stripped. Is this
correct, or am I missing some more nuanced automated style management
possibility?

3. I understand that I can write my own EditPaste event to have this
execute when the user pastes text. Is this a good idea, or is there
some better background event that might handle this? I'd like it to be
as seamless as possible.

Thanks for your time.
 
D

Dave Lett

If you only want to force the same font/size, then you can use something
like the following:

With ActiveDocument.Range.Font
.Name = "Arial"
.Size = 16
.Color = wdColorAutomatic
End With

However, that is direct formatting and if your "reset" the font, the core
style will take over and reapply the characteristics of the style.

HTH,
Dave
 
D

downwitch

Right, whereas find/replace leaves all style stuff alone, as far as I
can tell.

One other problem related to replacing the EditPaste event: when I have
copied using CTL+A from another document, I get an error message
telling me that find/replace is not available. I assume this has
something to do with beginning/end of document anchors and how Word is
resolving them? Is there a workaround so that even though a user
selects everything in a source document, these anchors don't get
pasted?
 

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