Borrar filtros
Borrar filtros

Replace text on Powerpoint using ActxServer

8 visualizaciones (últimos 30 días)
Sarah Reed
Sarah Reed el 19 de Jul. de 2023
Editada: Bhanu Prakash el 19 de Jul. de 2024
Hi,
I'm using actxserver to access powerpoint, and I would like to replace the 'UUU' text from every slide with a user inputted number. Some slides have UUU in the title, others have it in a body paragraph. Some have multiple instances on one slide. How can I replace them all?

Respuestas (1)

Bhanu Prakash
Bhanu Prakash el 19 de Jul. de 2024
Editada: Bhanu Prakash el 19 de Jul. de 2024
Hi Sarah,
You can replace all the occurrences of the text ‘UUU’ with a user input by following the workflow mentioned below:
1.Create an 'actxserver' for Powerpoint application and open the presentation:
actPPT = actxserver('PowerPoint.Application');
presentation = actPPT.Presentations.Open('path_to_pptx_file'); % replace 'path_to_pptx_file' with the complete path to the pptx file
2. As you want to replace all the occurrences of ‘UUU’, you will have to iterate through each slide to check if there are any text frames present. If there are any, then you can try replacing ‘UUU’ with the user input. Here is a sample code of how to do it:
% Iterate through each slide in the PPT
for i = 1:presentation.Slides.Count
% Iterate through each shape in the slide to check for any text frames
for j = 1:presentation.Slides.Item(i).Shapes.Count
shape = presentation.Slides.Item(i).Shapes.Item(j);
% Check if the shape has text
if shape.HasTextFrame
% Check if the text frame has text and replace any occurance of
% 'UUU' with user input
if shape.TextFrame.HasText
textRange = shape.TextFrame.TextRange;
textRange.Replace('UUU', userInput);
end
end
end
end
3. Once the replacing is done, you can save and close the presentation using the commands below:
presentation.Save;
presentation.Close;
4. Quit the Powerpoint and delete the server object using:
Quit(actPPT);
delete(actPPT);
If the 'userInput' is a number, then convert it to char and then try replacing it with 'UUU'. Also make sure that the you have edit access to the presentation.
For more information on the 'actxserver', you can refer to the following documenation:
Hope this helps!

Categorías

Más información sobre MATLAB Report Generator en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by