Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 12-08-2018, 02:08 PM
marna marna is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Dec 2018
Posts: 2
marna is on a distinguished road
Wink need help creating a Word macro selecting all and changing font, size, and color thanks

Can someone help please? Not sure how to do this.




I need to create a macro for Word which will:
Select All
Change the font to Arial
Change the size to 14
Change the color to Dark Blue (the default dark blue)


Any suggestions? Thanks, Marina
Reply With Quote
  #2  
Old 12-08-2018, 09:34 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 18,680
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

You should not be modifying a document that way. rather, you should create a Style with the desired characteristics (or modify an existing one) and apply that. For example, the following macro does what you ask by modifying & applying Word's 'Normal' Style:
Code:
Sub FormatActiveDocument()
Application.ScreenUpdating = False
With ActiveDocument
  With .Styles(wdStyleNormal).Font
    .Name = "Arial"
    .Size = 14
    .ColorIndex = wdDarkBlue
  End With
  With .Range
    .Style = wdStyleNormal
    .ParagraphFormat.Reset
    .Font.Reset
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 12-09-2018, 12:02 PM
marna marna is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Dec 2018
Posts: 2
marna is on a distinguished road
Default

Great! Thank you!


That's almost it. Two last things.


Can we add a Bold to that... and is there a way to run the macro on a bunch of files in a folder? Or do i need to open all the documents and run it one by one?


again thank you!
Marina
Reply With Quote
  #4  
Old 12-09-2018, 05:30 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 18,680
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Of course you can both of those things. I can't imagine why anyone would want to bold an entire document, though, let alone all documents in a folder; that suggests you're specified the wrong font. It would have helped, though, if you'd taken the time to specify the scope of the task from the outset.

Code:
Sub ReformatDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      With .Styles(wdStyleNormal).Font
        .Name = "Arial"
        .Size = 14
        .Bold = True
        .ColorIndex = wdDarkBlue
      End With
      With .Range
        .Style = wdStyleNormal
        .ParagraphFormat.Reset
        .Font.Reset
      End With
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Tags
font, font color, macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
When changing table style in Word 2010, font size seems to change but doesn't show in new tables heartsoulliving Word 1 12-07-2016 05:17 PM
Word macro doesn't change font color Spideriffic Word VBA 8 11-04-2015 03:47 AM
Changing the commentary font size in WORD 2013 to a larger one MikeD Word 3 06-01-2014 03:40 AM
MAcro to List all the Font & its size in a word document shaukat74 Word VBA 1 01-29-2013 09:34 PM
changing font size without changing leading carolns Word 1 09-14-2009 12:30 PM


All times are GMT -7. The time now is 12:59 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft