changing fonts within a range from inserted file contents

S

sylvian stone

Hi,

I've been searching the news archives, but can't seem to find a
workable solution to this problem - which I am sure is pretty easy.

I run some VBA code to insert several different documents into another
document based on selections within a user form.

There are hundreds of insertable documents (which I read into a
combobox for selection to the document) which apply a different font to
the main body of the document.

Most of the document is Tahoma size 11, while a lot of these Templates
is Times New Roman Size 12.

My first thought was to just modify the range. Each document is
inserted at a certain bookmark. So I use the following code to insert
the file:

Set myRange = objDoc.Bookmarks("detailed_recommendations").Range
myRange.InsertFile path & "my file.doc"


Then I have tried various combinations to modify the font of this
range:

i.e.:

myRange.Select

With myRange.Font
.Name = "Tahoma"
.Size = 11
End With


Nothing I seem to do seems to alters the font of the inserted text.
A lot of the inserted files contain mainly bulleted lists. Would this
make any difference ?

I'm sure this is very simple to sort out. Maybe I'm too simple to
figure this out.

Rgds
SS.
 
K

Klaus Linke

Hi Sylvain,

If the authors of those documents knew how to use Word, the formatting was
done with styles.
You don't want to mess up the documents completely by applying manual
formatting.

Change the styles the way you want:

Dim styleLoop As Style
For Each styleLoop In ActiveDocument.Styles
With styleLoop.Font
If .Name = "Times New Roman" And _
.Size = 12 Then
.Name = "Tahoma"
.Size = 11
End If
End With
Next styleLoop

Only if that doesn't work because the docs are ruined by manual formatting
already, you could try your code.

It should work. Probably you haven't set up myRange properly.
Set a breakpoint at myRange.Select and look if the text is really selected.
If it does work, you can remove that line. You don't need to select text to
format it, and it just slows down the macro.

Regards,
Klaus
 

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