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

Re: change font size of whole document by Stefan

Stefan
Mon Sep 10 08:35:56 CDT 2007

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


"FotoArt" wrote in message
news:5765F54A-92FA-4344-A3DE-281AA2E74079@microsoft.com...
> 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








Re: change font size of whole document by Helmut

Helmut
Mon Sep 10 09:33:02 CDT 2007

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"



Re: change font size of whole document by Helmut

Helmut
Mon Sep 10 10:03:51 CDT 2007


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


that should be:
msgbox activedocument.range.font.name = "Arial"
returns false!

Re: change font size of whole document by Helmut

Helmut
Mon Sep 10 11:44:30 CDT 2007

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"

Re: change font size of whole document by Stefan

Stefan
Tue Sep 11 02:38:20 CDT 2007

"Helmut Weber" wrote in message
news:hvjae3dr1k20k7ccf1iue32cflv0hdp5lo@4ax.com...
> 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.

--
Stefan Blom
Microsoft Word MVP




> 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"
>
>