change font size of whole document

F

FotoArt

hello everyone
Ihave the following code to change font size.
Its not working.
Also, how do I deselect the text after executing the code.

Selection.WholeStory
If Selection.Font.Name = "Tahoma" Then
Selection.Font.Size = 15
End If
any help will be appreciated

thanx
ahmed
 
S

Stefan Blom

In general, it is easier to work with ranges than with selections (and,
since ranges does not depend on the selection, there is no need to deselect,
either). For example, the following code:

If ActiveDocument.Content.Font.Name = "Tahoma" Then
ActiveDocument.Content.Font.Size = 15
End If

would change the font size of all text (in the body of the document) to 15pt
if the font name of that text is Tahoma.

But note that since you can specify the font on the character level, the IF
statement does not necessarily evaluate to TRUE.

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 
H

Helmut Weber

Hi FotoArt,

the easy thing at first.
selection.collapse

Then, there can be several issues.

If there are different fonts in the selection,
the condition would never be true.
To check it, try it with different fonts in the selection:

MsgBox Selection.Font.Name = "Arial"

Understandably, for sure.

But then, even if you have formatted
all of the doc in "Arial" and the doc is not quite small,
the condition would never be true.

I think I've read about that once,
but can't remember exactly.

However, for 11 pages of "The quick brwon fox",
the following code stops after character 21119!

Also
activedocument.range.font.name = "Arial"
returns false!

So you got to process smaller portions,
besides the first mentioned issue.

And google here for range vs. selection,
it's worth finding out the difference.


To the best of my knowledge.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

Sorry, ...

the following code:

Sub Macro3()
ActiveDocument.Range.Font.Name = "Arial"
MsgBox ActiveDocument.Range.Font.Name = "Arial"
ActiveDocument.Range(0, 0).Select
Dim lCnt As Long
Selection.ExtendMode = True
While Selection.Font.Name = "Arial"
Selection.MoveRight unit:=wdWord
Wend
MsgBox Selection.Characters.Count
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
S

Stefan Blom

in message
Hi FotoArt,

the easy thing at first.
selection.collapse

Then, there can be several issues.

If there are different fonts in the selection,
the condition would never be true.
To check it, try it with different fonts in the selection:

MsgBox Selection.Font.Name = "Arial"

Understandably, for sure.

But then, even if you have formatted
all of the doc in "Arial" and the doc is not quite small,
the condition would never be true.

I've read it too, somewhere, but I obviously didn't think of it when I
posted my reply. :-(

Thank you for clarifying this.
 

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