When I update the contents of a text box, then check its .height
property, I find that it does not reflect the new size of the textbox -
even though "resize autoshape to fit text" is checked in the textbox
shape!
For example, code like this:
set tmpObj = pptPresentation.Slides(1).Shapes(1)
height1 = tmpObj.height
tmpObj.TextFrame.TextRange.Text = "X" & vbCrLf & "Y" & vbCrLf & "Z"
height2 = tmpObj.height
When run normally, height2 has no value.
However, if I step through the code or if I put a MsgBox in there
somewhere, the values are correct.
Is it that Powerpoint is not updating the object fast enough for me to
inspect its properties? If so, is there some way for me to wait for it
to be ready, or to force it to "re-compute" the object so the height
property will be correct?
Thanks!
Matt Kruse
Dim oShp As Shape
Set oShp = ActivePresentation.Slides(1).Shapes(1)
oShp.TextFrame.AutoSize = ppAutoSizeShapeToFitText
oShp.TextFrame.TextRange.Text = "Line 1" & vbCrLf & "Line 2" & vbCrLf &
"Line 3"
--
Regards,
Shyam Pillai
Animation Carbon: http://skp.mvps.org/ac/
"Matt Kruse" <ma...@mattkruse.com> wrote in message
news:1124828549.5...@g44g2000cwa.googlegroups.com...
Great news! heh :)
It always seems to work from within Powerpoint as I'm editing the file,
but not via script.
> Could you try the following and let me know if it works.
> Dim oShp As Shape
> Set oShp = ActivePresentation.Slides(1).Shapes(1)
> oShp.TextFrame.AutoSize = ppAutoSizeShapeToFitText
> oShp.TextFrame.TextRange.Text = "Line 1" & vbCrLf & "Line 2" & vbCrLf &
> "Line 3"
I've tried that also and no luck.
I've tried setting AutoSize to 0, then inserting text, then setting it
back to 1, and it doesn't work. And about every other combination you
can imagine.
It seems that the core problem is that the resize doesn't take effect
unless a msgbox is shown or if I step through the code slowly. Like
it's waiting for a chance to re-flow the page in order to update it,
but the script executes so quickly that ppt never gets the chance to
update. That's what it seems to me, at least.
Thanks for the suggestion!
Matt
I would not be surprised if it solves your problem. If it does please let me
know here but thanks should go to Steve who helped me to solve a similar
problem with this suggestion some time ago.
--
JanAdam
With ActiveWindow.Selection.ShapeRange(1)
.Left = .TextFrame.TextRange.BoundLeft - .TextFrame.MarginLeft
.Top = .TextFrame.TextRange.BoundTop - .TextFrame.MarginTop
.Width = .TextFrame.TextRange.BoundWidth + .TextFrame.MarginLeft +
.TextFrame.MarginRight
.Height = .TextFrame.TextRange.BoundHeight + .TextFrame.MarginTop +
.TextFrame.MarginBottom
' Add this line just to turn the setting on.
.TextFrame.AutoSize = ppAutoSizeShapeToFitText
End With
--
Regards,
Shyam Pillai
Animation Carbon: http://skp.mvps.org/ac/
"Matt Kruse" <ma...@mattkruse.com> wrote in message
news:1124887810.1...@o13g2000cwo.googlegroups.com...