I'm very close to being complete with this macro. This is a macro that opens and scans a PowerPoint selected by the user and replaces all American English words with their Queen's English counterparts. (Analyze -> Analyse, Labor -> Labour). Highlights and prompts the user before each replace and notifies when done. What I'm hoping to do at this point is replace the static arrays I've written in the macro with two columns in my workbook. It works great as is, but I feel like there's a better way than to write out every word in the array as I have it now.
Basically:
In the PowerPoint file, if it finds a value within "B3:B116", replace with the corresponding value in "C3:C116".
Any insight here? Thank you!
Basically:
In the PowerPoint file, if it finds a value within "B3:B116", replace with the corresponding value in "C3:C116".
Code:
Sub US_QE()
'Open PowerPoint Document from Excel
Dim objPPT As Object
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
AppActivate Application.Caption
strFileToOpen = Application.GetOpenFilename _
(Title:="Please Choose PowerPoint")
If strFileToOpen = False Then
MsgBox "No file selected.", vbExclamation, "Sorry!"
GoTo Ending
End If
objPPT.Presentations.Open Filename:=strFileToOpen
'PowerPoint Variables
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.presentation
Dim fnd As Variant
Dim rplc As Variant
Dim FindArray As Variant
Dim ReplaceArray As Variant
Dim TxtRng As PowerPoint.TextRange
Dim TmpRng As PowerPoint.TextRange
Dim sld As PowerPoint.Slide
Dim shp As PowerPoint.Shape
[COLOR="#FF0000"]
'WORKING ON PULLING FROM EXCEL
'Dim rg As Range
'Dim rg2 As Range
'Set rg1 = ThisWorkbook.Worksheets("Sheet1").Range("B3:B116")
'Set rg2 = ThisWorkbook.Worksheets("Sheet1").Range("C3:C116")[/COLOR]
'Find/Replace Variables
FindArray = Array("analyze", "Analyze", "annualize", "Annualize", "annualize", "Capitalize", "capitalize", "nationalize", "Nationalize", "capitalization", "Favor", "favor", "Labor", "labor")
ReplaceArray = Array("analyse", "Analyse", "annualise", "Annualise", "annualise", "Capitalise", "capitalise", "nationalise", "Nationalise", "capitalisation", "Favour", "favour", "Labour", "labour")
'Loop Through Each Slide
For Each sld In objPPT.ActivePresentation.Slides
objPPT.Activate
objPPT.ActiveWindow.View.GotoSlide sld.SlideIndex
For y = LBound(FindArray) To UBound(FindArray)
For Each shp In sld.Shapes
fnd = FindArray(y)
rplc = ReplaceArray(y)
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
Set TxtRng = shp.TextFrame.TextRange.Find(fnd, 0, True, WholeWords:=msoFalse)
If TxtRng Is Nothing Then GoTo NextTxtRng
TxtRng.Select
AppActivate Application.Caption
If MsgBox("Replace " & fnd & " with " & rplc & "?", vbYesNo + vbSystemModal) = vbYes Then Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _
ReplaceWhat:=rplc, WholeWords:=False, MatchCase:=True)
End If
End If
'Replace Other Instances (if necessary)
Do While Not TmpRng Is Nothing
Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _
ReplaceWhat:=rplc, WholeWords:=False, MatchCase:=False)
Loop
'If Text Range is Nothing:
NextTxtRng:
Next shp
Next y
Next sld
AppActivate Application.Caption
MsgBox "US replaced with QE"
'If no PowerPoint selected:
Ending:
End Sub
Any insight here? Thank you!