Changing background color in multiple files?

M

MICROSOFT

I want to change the background color in hundreds of .doc files. To do so
one at a time would take hours. Is there any way of doing this for all
the files at once?
 
G

Graham Mayor

The burning question is 'why'? If you need to print coloured backgrounds the
best answer is to print on coloured paper.
Most printer drivers will not allow you to print to the edge of the paper
(and if they did the consumption of ink would be astronomical) and so you
will get a white edge all the way around the document.
If insist in this folly, then the following macro will do the trick for all
the documents in a folder (provided they are not protected). Change the RGB
colour index RGB(102, 204, 255) for the actual background colour index you
want to use. http://www.gmayor.com/installing_macro.htm

Sub BatchProcess()
Dim strFilename As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , _
"List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" _
Then strPath = strPath + "\"
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strFilename = Dir$(strPath & "*.doc")

While Len(strFilename) <> 0
Set oDoc = Documents.Open(strPath & strFilename)

'
'Do what you want with oDoc
'
oDoc.Background.Fill.ForeColor = RGB(102, 204, 255)
oDoc.Background.Fill.Visible = msoTrue
oDoc.Background.Fill.Solid
oDoc.Close SaveChanges:=wdSaveChanges
strFilename = Dir$()
Wend
End Sub
 
M

MICROSOFT

This is 2010. The need for printing is very low. Its almost always for
people living in the last century.
But the main reason is its so much easier on the eyes reading black text
on a darker background. I find gray is nice but any darker color is nice.
 
M

MICROSOFT

You could modify the method in the article "Find & ReplaceAll on a
The whole website isn't working now but I'll try later.

OK - working now. I'm very unversed in VBA stuff. Sort of like looking
at Greek for me. Is there any other way of doing a batch background color
change?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top