I am struggling to find out how to vertically align textboxes via VBA.
Furthermore, when researching the Autofit feature of Powerpoint, I found quite some posts, that said this can only be changed in the registry, but on my PC, some templates autofit and some don't., Is there some way to turn it off when creating the placeholders in VBA?
Thanks for the help
seba
AutoFit can be turned on/off for shapes that have text frames (ie, that can contain text):
Assuming a reference to the shape in oSh,
oSh.TextFrame.AutoSize = ppAutoSizeNone ' or ppAutoSizeShapeToFitText
' 0 or 1 respectively
Related
I'm trying to write a PowerPoint VBA macro that would act differently whether a shape is merely selected or is in edit mode (i.e. the cursor to edit the text is present, see image).
Is there a way to check this using VBA in PowerPoint? I haven't been able to find on this anything so far
My ultimate goal being:
If just the shape is selected, the macro will align the shape left
If the shape is in edit mode, the macro will align the text left (and leave the shape where it is)
Any help would be appreciated
Best
You can do this by using Selection.Type. If it returns 2, the shape is selected. If the insertion point is in the text, it will return 3:
Sub DetectShapeOrText()
MsgBox ActiveWindow.Selection.Type
End Sub
PpSelectionType enumeration (PowerPoint)
I'm working on creating a PowerPoint template for daily class presentations. In the template I'd like to have a hunk of text that is prominently displayed on the first slide and which repeats at the bottom of the subsequent slides at the bottom in a smaller size. The text will change every day.
The ideas I've had so far:
Use a text field. As far as I can tell, PowerPoint doesn't have anything like a text field that can be dynamically set.
Use a footer - this works and I can modify the master to get the look I want, but I'd really like to be picking up the value of the text from the first page so that edits would be automatically applied and to save the initial step of setting the footer.
Using VBA - I'd be willing to give this a shot, but I've never used VBA and the learning curve seems steep so it would be nice to know if the idea is feasible in VBA.
Can this be done? How would you approach it?
Here's an example of what I'm hoping to be able to do. Ideally the solution would work on both the Mac (2013) and Windows (2016) version of PowerPoint.
You can connect your presentation with an excel file. And running the code in the ppt would pull out the text in the excel file and update the titles instantly.
Create a presentation with a textbox with some temporary text. Put the below code in ppt. save as pptm.
Sub AddMotionPath()
Dim Temp As String
Excel.Application.Workbooks.Open ("D:\Users\Desktop\Book1.xlsx") ' update the path of the excel file
Workbooks("Book1.xlsx").Activate 'activate the file
For p = 1 To 4
Temp = Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("B" & p + 1).Value ' Column B has the titles
ActivePresentation.Slides(p).Shapes(1).TextFrame.TextRange.Text = Temp ' this updates the titles from excel to ppt slide
Next
Excel.Application.Workbooks("Book1.xlsx").Close False 'closes the excel file
End Sub
Let me know if this works for you. You can update the excel file and run the macro in ppt. The text in the slides will be updated automatically.
I would like to select all characters in a Powerpoint textbox (Version 2010) that have a certain defined style (e.g. all bold characters). Manually, one can create a non-contiguous text selection in a single text box by simply holding the control key while selecting. With VBA, I failed so far. This is my very simple approach:
Dim c As TextRange
For Each c In ActiveWindow.Selection.ShapeRange(1).TextFrame.TextRange.Characters
If c.Font.Bold Then c.Select
Next c
While this all works nicely when going through this stepwise, the c.Select will always "unselect" what was selected before and there is no option to extend the selection (unlike with shape selections). I end up with just the last bold character being selected.
The selection itself is what I want as end result to give the user the option to further modify the font etc.
Does anyone have a suggestion (or is this not at all accessible via VBA?)
Thanks a lot
I am trying to help a co-worker with some Word 2007 picture formatting. I would like to be able to update the Border style, drop-shadow, etc. by assigning the pictures one of the named styles that you can select from the Picture Formatting tab in the ribbon. The style I am trying to use is called 'Simple Frame, Black'. Unfortunately, I haven't found any documentation in the Object Model Reference about using these styles for InlineShapes.
I tried recording a macro, both by using the mouse to go through the steps, and only using the keyboard to do what I want, but none of the picture style assignment steps show up in the resulting vba module.
I found a question that is similar on egghead here
From this, it sounds as though maybe this functionality isn't exposed in the Object model. I'm wondering if anyone has found a way to do this, and if not, what the best way to get around it would be.
Thanks,
Spencer
As far as I can tell there isn't a way to directly set the named picture styles from VBA. It is a little time consuming but my suggestion would be to insert two pictures into a word document, apply the formatting to one of them, then examine both objects in the VBE Watch window.
Based on my experience with Word 2010, the things to pay attention to are: Borders, Fill, Glow, PictureFormat, Reflection, Shadow, & SoftEdge.
In Word 2010 to change a picture without formatting to have the same formatting as the 'Simple Frame, Black' style apply the following changes:
With ThisDocument.InlineShapes(1)
.Borders.OutsideLineStyle = wdLineStyleSingle
.Borders.OutsideLineWidth = wdLineWidth300pt
With .Shadow
.Blur = 4
.OffsetX = 2.12132
.OffsetY = 2.12132
.Style = msoShadowStyleOuterShadow
.Transparency = 0.57
.Visible = msoTrue
End With
End With
The Shadow Blur and Offsets are minor changes you can't really see.
Ok, So I'm constantly battling with Microsoft as I'm creating several templates for a few customers. My problem is this, simple textbox placeholders scattered all around a document allows me to press TAB to go to the next placeholder. Much like Tab order in Visual Studio. But for some strange reason, this doesn't work with rich textbox placeholders. And I need to use rich text for a few textboxes because the user should be allowed to alter the formatting of single characters. This is not possible with simple textboxes.
So I was thinking, could this be possible using macros? For example, if a textbox placeholder is selected and the macro is run, go to the next placeholder?
The Shape/TextBox objects can be accessed through
ThisDocument.Shapes.Item(index)
and checking the returned Shape object for
theShape.Type = msoTextBox
However, the Shape objects will be returned in the order that they were created, not their order on the page/document. To find the 'next' TextBox, you are probably going to have to loop through all TextBoxes and investigate their location (.Top, .Left etc) in order to find the correct one to move to with:
theNextShape.Select