![]() 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 see there is also a boundheight property, for autosizing rows.I am attempting to automatically generate reports as PowerPoint presentations. Quite a long way down the chain from the table cell object. I spent ages trying to find a property/method of the "autofit" type for table cells in powerpoint vba. Had thought of posting the code here, but it exceeds the limit on number of characters Is there a way to post vba code to this forum?ĭim icol As Integer, irow As Integer, minW As Single Once all the cells are done, the text box is deleted. My solution was to create (programmatically) a text box, put the text of the cell into the text box (together with font size and font name), resize the text box, get width and height of the text box, and use these values to set width and height of the cell in the table. I had much the same challenge as icu222much – wanting to use vba to automate the resizing of tables to match cell contents. MySlide.Shapes().Table.Cell(ta rgetRow, targetColumn). = ppAutoSizeShapeToFitText MySlide.Shapes().Table.Columns (x).Width = ppAutoSizeShapeToFitText MySlide.Shapes().Table.Cell(x, y). = ppAutoSizeShapeToFitText MySlide.Shapes().Table.Cell(x, y). = msoFalse I am wondering how I would go abouts in doing this?īelow are my various attempts but they have failed as when I went to run my macro, the column widths did not change. I would like to resize selected columns so the width of the column does not exceed the width of the longest data – in otherwords make the column width the perfect fit. I have a table in PowerPoint with several rows and columns of data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |