0
votes

Using PowerPoint 2016, I am writing a macro that allows the user to input data in a live presentation using UserForms and TextBoxes. This is working nicely, except when i try to display the text in a SmartArt. The following macro illustrates the problem:

Sub writeToSmartArt()
    Dim artShape As Shape
    Set artShape = ActivePresentation.Slides(maalSlide).Shapes("Diagram")
    MsgBox artShape.SmartArt.Nodes(1).Nodes(1).TextFrame2.TextRange.Text
    artShape.SmartArt.Nodes(1).Nodes(1).TextFrame2.TextRange.Text = "testing" 
End Sub

The sub sets the SmartArt shape to the artShape variable, and first prints out the contents of a specified node in a MsgBox. In the next step, I am setting the text property to a new value. Everything works fine as long as the presentation is not active. I am able to manually run the sub, and everything behaves as expected. However, when the slideshow is running i get the following error message when trying to write to the SmartArt node:

    Run-time error '-2147467259 (80004005)':
    Method 'Text' of object 'TextRange2' failed

Displaying the current content in the MsgBox still works. How can i overcome this problem?

2

2 Answers

0
votes

Not sure why you get an error in slideshow mode. However, a workaround would be to use the node's Shape() method to access the shape directly, instead of the node itself, like so: artShape.SmartArt.Nodes(1).Nodes(1).Shapes(1).TextFrame2.TextRange.Text = "testing". Hope this helps!

0
votes

I had the same problem, so instead use SmartArt.Nodes(), I am using SmartArt.AllNodes().

Exemple:

ppt_output.Slides(SLIDESMART).Shapes("TheList").SmartArt.AllNodes(1).Shapes.TextFrame2.TextRange.Text