Поиск и замена текста в Powerpoint 2010 из Excel 2010 с помощью VBA

Я успешно использовал этот код в модуле Powerpoint, но когда я перемещаю его в свой модуль Excel, возникает несколько проблем. Я встроил приложение Powerpoint на лист 1 Excel. Цель состоит в том, чтобы сгенерировать PowerPoint из Excel и заменить название компании всякий раз, когда оно появляется на слайде PowerPoint, новым названием компании из диапазона Excel. Я получаю сообщение об ошибке 429 Компонент ActiveX не может создать объект в разделе «Для каждого osld в ActivePresentation.Slides. Моя презентация Powerpoint не активна? Будем признательны за любую помощь. Использование Excel/Powerpoint 2010.

Sub changeme(sFindMe As String, sSwapme As String) 
Dim osld As Slide 
Dim oshp As Shape 
Dim otemp As TextRange 
Dim otext As TextRange 
Dim Inewstart As Integer 



For Each osld In ActivePresentation.Slides 
For Each oshp In osld.Shapes 
    If oshp.HasTextFrame Then 
        If oshp.TextFrame.HasText Then 

            Set otext = oshp.TextFrame.TextRange 
            Set otemp = otext.Replace(sFindMe, sSwapme,, msoFalse, msoFalse) 
            Do While Not otemp Is Nothing 
                Inewstart = otemp.Start + otemp.Length 
                Set otemp = otext.Replace(sFindMe, sSwapme, Inewstart, msoFalse, msoFalse) 
            Loop 

        End If 
    End If 

Next oshp 
Next osld 
End Sub 
 '-------------------------------------------------------------------------
Sub swap() 
Dim sFindMe As String 
Dim sSwapme As String 
Dim ppApp As PowerPoint.Application 
Dim ppPreso As PowerPoint.Presentation 

 'Start Powerpoint

 'Look for existing instance
On Error Resume Next 
Set ppApp = GetObject(, "PowerPoint.Application") 
On Error Goto 0 

 'Create new instance if no instance exists
Set ppApp = CreateObject("Powerpoint.Application") 



 'Open Template in word
With Sheets("Sheet1").Shapes("Object 1").OLEFormat.Verb(Verb:=xlVerbOpen) 
End With 
 'Make it visible
ppApp.Visible = True 



sFindMe = "Name To Find" 
 'change this to suit
sSwapme = "New Name" 
Call changeme(sFindMe, sSwapme) 
 'sFindMe = "<find2>"
 'sSwapme = ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange
 'Call changeme(sFindMe, sSwapme)
End Sub 
5
задан Community 9 July 2018 в 19:34
поделиться