View Single Post
 
Old 11-23-2015, 08:58 AM
gedinfo gedinfo is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Nov 2015
Posts: 2
gedinfo is on a distinguished road
Smile How do I set selection to the active document?

Hi,

I want to be able to run a macro on a Word 2010 document that i currently have open.
The code below shows the working macro with an open call, what I want to do is run the macro on any opened document, without having to manually set the file.

Any suggestions?

Thank you.


Code:
Sub FontReplaceTimesNewRoman()
'
' FontReplaceTimesNewRoman Macro
'
'
Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document
Dim objSelection As Selection
Dim FileString As String
Const wdReplaceAll = 2

    Set objWordApp = CreateObject("Word.Application")
    FileString = "C:\Downloads\VerificationProcedures.docx"

    objWordApp.Documents.Open (FileString)
    objWordApp.Visible = True

    Set objWordDoc = objWordApp.ActiveDocument
    Set objSelection = objWordApp.Selection

    objSelection.Find.Font.Name = "Times New Roman"
    objSelection.Find.Forward = True
    objSelection.Find.Replacement.Font.Name = "Calibri"
    objSelection.Find.Execute "", , False, , , , , , , , wdReplaceAll

    objWordApp.Documents.Close (Word.WdSaveOptions.wdSaveChanges)
    objWordApp.Quit
    Set objWordApp = Nothing
End Sub
Reply With Quote