Thomas Weller
Thomas Weller

Reputation: 59605

Change text only temporarily

I want to change the text of a Powerpoint shape only during presentation (i.e. while the slide is shown), but not change the text permanently so that it modifies the PPT file.

Currenty I'm subscribing to the event

Application.SlideShowNextSlide += OnNextSlide;

and then I change the text on one specific shape like this:

shape.TextFrame.TextRange.Text = "Hello world";

However, when the presentation ends, that text is in the PPT file and Powerpoint asks me whether I want to save the changes.

I want to avoid that my Powerpoint Add-In makes changes to the file.

Upvotes: 1

Views: 82

Answers (2)

oetoni
oetoni

Reputation: 3907

UPDATE Based on Steve's answer and your feedback in the comments. So here is an idea for you:

Why don't you just do the code that we mentioned, add Steve's line (it's actually a good way to avoid save questions), and since you'd have restore the original value at the end then just save through programmatic function in C# no matter what. So that even if the user has done any changes you would have saved file...no questions asked ;)

step by step: 1) run like normally 2) add Steve's remark 3) do the trick with the variable change I mentioned bellow 4) do save no matter what at the end of the presentation so that any user changes are saved with the document

code snippet for saving are in this answer very well documented

Remark: Remaining issues with this logic is only when the user does intentional changes and at the end does not want to save the work but this is a case not foreseen above. All the other users will not have to suffer through the "Want to save?" question :)


try to save previous state first and then before moving away or closing re-assign that old value back to it ;)

1st do

String oldValue = shape.TextFrame.TextRange.Text;

if you need to store outside the frame, use IO to store on file temporary or pass the variable on an outside function/variable value. Then do your code

shape.TextFrame.TextRange.Text = "Hello world";

and after you finish just do again

shape.TextFrame.TextRange.Text = oldValue;

or read the value from where you left it :)

hope it helps

Upvotes: 1

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

In addition to the suggestion @oetoni made, you'll want to set the presentation's .Saved state to True after making each change or before allowing the user to quit the show/presentation.

That way, PowerPoint won't think any changes have been made, so won't offer to save the presentation when the user quits.

ActivePresentation.Saved = True

Upvotes: 0

Related Questions