So this looks like PowerPoint can't refresh the content while code is running and/or a window is in view when the code finishes. The same happens if I run it with a visible window and with your last two lines commented out. When the code is interrupted, you can see that the AutoSize works and when it's left to run freely, AutoSize doesn't work. I then set a break point on your SaveAs line. I tested the theory that PowerPoint isn't updating the view until the code stops by changing one line of your code: Set pres = (WithWindow:=msoFalse) So, it appears that the AutoSize function isn't being applied even if you set the pres to have a visible (minimised or other) window because the pres is closed before PowerPoint has a chance to update it. So it seems the auto fit feature is working for me. On moving the mouse over the PowerPoint stack of thumbnails in the Windows task bar, I could already see that the text size had been reduced. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna." Presentations(1).Slides(1).Shapes(1).="Lorem ipsum dolor sit amet, consectetuer adipiscing elit. I then minimised the window, created a new presentation (so that becomes the active window) and then programmatically added a long string of text to the shape in the first presentation via the VBE Immediate window: TextFrame2.AutoSize = msoAutoSizeTextToFitShape ' Shrink text on overflow I made a very simple test by adding a text box to an empty slide. H_max = textbox.Height - tf.MarginTop - tf.MarginBottomĭebug.Print "Iteration: " & iLoop & " Overflow: " & overflow ' Get the max height for the text to fit in the box. I'd still like to know if there's a way to let PowerPoint's autofit do it's thing, so I'll leave the question open. I added some indent levels to verify that the levels with different font sizes are all scaling in a relative fashion. The code used below as a workaround to manually scale the text is commented out.Īs a compromise workaround, the following code reduces the font size until the text fits. Here is a PowerPoint file with the macro that created the auto-generated file. Editing text, hiding the slide, adding a slide, etc, will force an update that will trigger the auto-fit behavior. Here is a link to a file generated without ever showing the PowerPoint Application window. I'm actually doing this with Python using a combination of python-pptx and COM, but the VBA example does the same behavior and I figure this example is much easier for folks to play with than the same thing from another programming language. This behavior likely exists in other versions as well. Remember to update the SaveAs filename to be a valid folder on your system for it to work. Pres.SaveAs FileName:="D:\Documents\Python\powerpoint\vba_demo.pptx" The following is a minimal example to demonstrate the problem: Sub new_presentation() Performing these same actions from VBA while the presentation is hidden does not trigger the font size update.ĭoes anyone know how to trigger PowerPoint's font auto-fit behavior without displaying the application window? Hiding and then re-showing the slide also successfully updates the font. If I then open the presentation and modify the text box in any way, the font then shrinks. When I make a presentation with the application window hidden, this auto-fitting doesn't occur. This is perhaps because the act of actually rendering the text is what informs PowerPoint that an overflow has occurred and a font down-size is then triggered. This behavior apparently only activates when the application is visible. If the shape is set so that text must fit the shape (which is the default), then the font sizes of all text in the shape are reduced automatically as text is added. The feature that is currently not working nicely is PowerPoint's automatic text auto-fitting that occurs when text overflows the boundaries of a shape. I am attempting to automatically generate reports as PowerPoint presentations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |