conditional macro

  • Thread starter Thread starter Eran
  • Start date Start date
E

Eran

I have saved thousands of pages in hundreds of folders. (PhD).
have used Calibri 8 and Calibri 10.
I now have to change the Calibri 8 to Calibri 10 and the Calibri 10 to
calibri 12.
I have used this (see below) and few other varients of this macro, but to no
avail.
may somebody please suggest a solution.
many thanks
EW
p.s. "Find / replace" will not work as their are 1000's of pages.
Sub A()
'
Selection.WholeStory
With Selection.Font
If ActiveDocument.Range.Font.Size = 10 Then
ActiveDocument.Range.Font.Size = 12
Else
If ActiveDocument.Range.Font.Size = 8 Then
ActiveDocument.Range.Font.Size = 10
End If
End If
End With
ActiveDocument.Save
End Sub
 
If all of the paragraphs use just one font size, then you could use

Dim i As Long
With ActiveDocument
For i = 1 To .Paragraphs.Count
.Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size + 2
Next i
End With

However, if you have different font sizes within paragraphs, you would have
to do it on a Word by Word basis using

Dim i As Long
With ActiveDocument
For i = 1 To .Words.Count
.Words(i).Font.Size = .Words(i).Font.Size + 2
Next i
End With

If you moved all of the files into one folder, you could incorporate the
relevant of the above pieces of code into a modification of the code in the
article "Find & ReplaceAll on a batch of documents in the same folder" at:

http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

to process all of the documents in one go.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
I would test this on COPIES of your files, but maybe something like

Sub ChangeFontSize()
Dim rFont As Range
Dim vOldSize As Variant
Dim vNewSize As Variant
Dim i As Long
vOldSize = Array(10, 8, 10.5, 12.5)
vNewSize = Array(12.5, 10.5, 10, 12)
For i = 0 To UBound(vOldSize)
Selection.HomeKey wdStory
With Selection.Find
.Font.Size = vOldSize(i)
Do While .Execute(Forward:=True) = True
Set rFont = Selection.Range
rFont.Font.Size = vNewSize(i)
Selection.Collapse wdCollapseEnd
Loop
End With
Next i
End Sub

If you wish to batch process a while folder full of documents then

Sub ChangeFontSize()
Dim strFile As String
Dim strPath As String
Dim oDoc As Document
Dim rFont As Range
Dim vOldSize As Variant
Dim vNewSize As Variant
Dim i As Long
Dim fDialog As FileDialog

vOldSize = Array(10, 8, 10.5, 12.5)
vNewSize = Array(12.5, 10.5, 10, 12)
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder containing the documents to be modifed and
click"
OK ""
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
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
strFile = Dir$(strPath & "*.do?")

While strFile <> ""
Set oDoc = Documents.Open(strPath & strFile)
For i = 0 To UBound(vOldSize)
Selection.HomeKey wdStory
With Selection.Find
.Font.Size = vOldSize(i)
Do While .Execute(Forward:=True) = True
Set rFont = Selection.Range
rFont.Font.Size = vNewSize(i)
Selection.Collapse wdCollapseEnd
Loop
End With
Next i
oDoc.Close SaveChanges:=wdSaveChanges
strFile = Dir$()
Wend
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Hi Doug
Would this work with percentages? i.e.:-
.Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size +
5%
or
.Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size
105%
???
Thanks
Phil (trying to keep my colleagues happy with nice buttons)
 
Use

.Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size * 1.05


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Hi Doug
Would this work with percentages? i.e.:-
.Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size +
5%
or
.Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size
105%
???
Thanks
Phil (trying to keep my colleagues happy with nice buttons)
 
Use

.Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size * 1.05


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Hi Doug
Would this work with percentages? i.e.:-
.Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size +
5%
or
.Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size
105%
???
Thanks
Phil (trying to keep my colleagues happy with nice buttons)
 
Use

 .Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size * 1.05

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com


Hi Doug
Would this work with percentages? i.e.:-
     .Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size +
5%
or
     .Paragraphs(i).Range.Font.Size = .Paragraphs(i).Range.Font.Size
105%
???
Thanks
Phil (trying to keep my colleagues happy with nice buttons)

Thanks for that, most helpful.
Phil
 
Back
Top