?
Solved

Style changes

Posted on 2003-03-02
14
Medium Priority
?
163 Views
Last Modified: 2010-04-07
I have alot of documents which have been created with times new roman font and  I want to create a macro button which can be seen on the toolbar as a button  which will automatically change the font in a document which is times new roman 12  to arial 11 ....any suggestions
0
Comment
Question by:Leaner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 3

Expert Comment

by:DocM
ID: 8054308
These documents are in what format? Doc? RTF?
0
 
LVL 1

Expert Comment

by:Belfry
ID: 8054385
yep,you have to go through the following steps:
1)check every character to see whether its font name is "Times New Roman";
2)if yes, check again to see if its font size is 12;
3)if both are true, change its font name and size;

this is the code fragment for you:

'way to see a cell's font name and font size:
Range("A1").Select
if Selection.Font.Name="Times New Roman" and Selection.Font.Size=12 then
Selection.Font.Name="Arial" 'change it to arial
Selection.Font.Size=11      'change the size
End if
0
 

Author Comment

by:Leaner
ID: 8054433
Doc files
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Leaner
ID: 8054485
its not excel so the range does not work
0
 

Author Comment

by:Leaner
ID: 8054569
its not excel so the range does not work
0
 
LVL 1

Expert Comment

by:Belfry
ID: 8055094
yep,you have to go through the following steps:
1)check every character to see whether its font name is "Times New Roman";
2)if yes, check again to see if its font size is 12;
3)if both are true, change its font name and size;

this is the code fragment for you:

'way to see a cell's font name and font size:
Range("A1").Select
if Selection.Font.Name="Times New Roman" and Selection.Font.Size=12 then
Selection.Font.Name="Arial" 'change it to arial
Selection.Font.Size=11      'change the size
End if
0
 
LVL 1

Expert Comment

by:Belfry
ID: 8055116
sorry,if it's word.document, see the following:

Sub reformat()
Dim n As Long, i As Long
'first get the number of characters in the document
Selection.WholeStory
n = Selection.Characters.Count
'then move to the first character to begin reformatting
Selection.HomeKey unit:=wdStory
Do
'select one character each time
  Call Selection.MoveRight(unit:=wdCharacter, Count:=1, Extend:=wdExtend)
  i = i + 1 'count of reformatted characters
  If i = n Then Exit Do 'if all reformtted, exit
  If Selection.Font.Name = "Times New Roman" And Selection.Font.Size = 12 Then'check name and size
'if meet the standard, change it
    Selection.Font.Name = "Arial"
    Selection.Font.Size = 11
  End If
  'deselect by moving right
  Call Selection.MoveRight(unit:=wdCharacter, Count:=1)
Loop
'move the cursor back to the beginning of the document
Selection.HomeKey unit:=wdStory

End Sub
0
 
LVL 3

Accepted Solution

by:
DocM earned 75 total points
ID: 8059496
‘Start of code
‘---------------------
Sub ChangeFontTo_Arial_11()
Selection.WholeStory
With Selection.Font
.Name = "Arial"
.Size = 11
End With
Selection.HomeKey unit:=wdStory
End Sub
‘End of Code
‘------------------------

Select the above code, and click on the menu Edit/Copy
1. Open MsWord

‘ In MsWord
2. Menu Tools/Macro/Visual Basic Editor

‘In Microsoft Visual Basic Editor
3. Menu View/Project Explorer
4. Click on Normal
5. Menu Insert/Module
6. Menu Edit/Paste
7. Menu File/Close and Return to Microsoft Word

‘ In MsWord
8. Menu View/Toolbars/Customize
9. Click on the Toolbars tab
10. Click on New
11. Click OK
12. Click on the Commands tab
13. Under Categories, click on Macros
14. Under Macros, select the macro ChangeFontTo_Arial_11 and Drag-drop it on your new toolbar.
15. Drag your new toolbar with the other toolbars
16. End of process

0
 

Author Comment

by:Leaner
ID: 8067340
Belfry you suggestion works well but it takes a while for it to complete( I know this is because its checking for  the times new roman)  - you dont have a quicker way for this to done
0
 

Author Comment

by:Leaner
ID: 8067655
Belfry you suggestion works well but it takes a while for it to complete( I know this is because its checking for  the times new roman)  - you dont have a quicker way for this to done
0
 

Author Comment

by:Leaner
ID: 8068058
Would anyone know how to change the normal style through a macro ?
0
 
LVL 1

Assisted Solution

by:Belfry
Belfry earned 75 total points
ID: 8086505
Ok, after testing, I think this should work well and fast:

Public Sub ReplaceFont()
    Selection.WholeStory   'Select All
    Selection.Find.ClearFormatting  'Clear previous format
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Font.Name = "Times New Roman" 'fontname to find
        .Font.Size = 12 'fontsize to find
        .Replacement.Font.Name = "Arial" 'fontname to replace
        .Replacement.Font.Size = 11  'fontsize to replace
        .Text = "" 'find all
        .Replacement.Text = "" 'replace all
        .Forward = True  'top down search
        .Wrap = wdFindStop 'when done, don't search again from top
        .Format = True ' use format
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll  'all done hear
Selection.HomeKey unit:=wdStory 'return to the beginning of document
End Sub
0
 

Expert Comment

by:CleanupPing
ID: 8900886
Leaner:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9012083
Moderator, my recommended disposition is:

    Split points between: DocM and Belfry

DanRollins -- EE database cleanup volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question