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 / November 2006

Tip: Looking for answers? Try searching our database.

Getting and setting font size of found text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BP - 27 Nov 2006 14:26 GMT
Dear Friends,

I'm trying to write a macro that reduces the size of each
chunk of text formatted with a specific font to a percentage
of the font size of that chunk, i.e. if a certain chunk of
text is 18pt Arial it should become 10.5pt Arial (yes I know
18*0.6 = 10.8, but Word apparently rounds down to the
nearest half point, which is good enough for me), if another
chunk is 12pt Arial it should become 7pt (~7.2) and so on.
The macro I've written is as follows:

* Sub Smaller()
*     With Selection.Find
*         .ClearFormatting
*         .Font.Name = "Arial"
*         mySize = Selection.Font.Size
*         With .Replacement
*              .Font.Size = mySize * 0.6
*         End With
*         .Execute Replace:=wdReplaceAll, Forward:=True, _
*         Wrap:=wdFindContinue
*     End With
* End Sub

It does wrong in that it sets all text formatted in Arial to
.6 times the size of the first character in the document --
regardless of what font it is. Can someone tell me how to
correct this?

TIA,

/BP
Greg Maxey - 27 Nov 2006 14:40 GMT
Try:
Sub Scratchmacro()
Dim oRng As Word.Range
Dim pSize As Double
Set oRng = ActiveDocument.Range
With oRng.Find
 .Font.Name = "Arial"
 While .Execute
   With oRng
     pSize = oRng.Font.Size
     pSize = pSize * 0.6
     oRng.Font.Size = pSize
     .Collapse wdCollapseEnd
   End With
 Wend
End With

End Sub

> Dear Friends,
>
[quoted text clipped - 28 lines]
>
> /BP

Rate this thread:






 
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.