Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Style changes

Posted on 2003-03-02
14
Medium Priority
?
164 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

572 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