Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"resize autoshape to fit text" doesn't change .height in a macro

5 views
Skip to first unread message

Matt Kruse

unread,
Aug 23, 2005, 4:22:29 PM8/23/05
to
I am populating a PPT file via a VB macro within Excel.
Everything works fine, except the following:

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

Shyam Pillai

unread,
Aug 23, 2005, 11:07:40 PM8/23/05
to
Matt,
The resize autoshape has always been a little flaky. It works sometimes and
sometimes it does not.
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"


--
Regards,
Shyam Pillai

Animation Carbon: http://skp.mvps.org/ac/


"Matt Kruse" <ma...@mattkruse.com> wrote in message
news:1124828549.5...@g44g2000cwa.googlegroups.com...

Matt Kruse

unread,
Aug 24, 2005, 8:50:10 AM8/24/05
to
Shyam Pillai wrote:
> The resize autoshape has always been a little flaky. It works sometimes and
> sometimes it does not.

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

JanAdam

unread,
Aug 24, 2005, 5:46:04 PM8/24/05
to
Try inserting
DoEvents
instead of your MsgBox

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

Shyam Pillai

unread,
Aug 24, 2005, 11:32:15 PM8/24/05
to
Matt,
The alternative is to resize the shape with code.

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...

0 new messages