Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

change font size of whole document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FotoArt - 10 Sep 2007 13:32 GMT
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
Stefan Blom - 10 Sep 2007 14:35 GMT
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.

Signature

Stefan Blom
Microsoft Word MVP

> hello everyone
> Ihave the following code to change font size.
[quoted text clipped - 9 lines]
> thanx
> ahmed
Helmut Weber - 10 Sep 2007 15:33 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber - 10 Sep 2007 16:03 GMT
>Also
>activedocument.range.font.name = "Arial"
>returns false!

that should be:
msgbox activedocument.range.font.name = "Arial"
returns false!
Helmut Weber - 10 Sep 2007 17:44 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Stefan Blom - 11 Sep 2007 08:38 GMT
> Hi FotoArt,
>
[quoted text clipped - 14 lines]
> 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.

Signature

Stefan Blom
Microsoft Word MVP

> I think I've read about that once,
> but can't remember exactly.
[quoted text clipped - 13 lines]
>
> To the best of my knowledge.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.