PDA

View Full Version : Macro Picks 1st Slide Not the Slide I'm On



nullpointer
08-01-2016, 08:43 AM
I use the following macro for adding a text box. Problem is, it always picks the first slide in the presentation and I need it to pick the slide I'm currently on to run the macro.


Sub Text_Regular_Black() Dim myTextBox As Shape
With ActivePresentation.Slides(1)
Set myTextBox = .Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, Left:=100, Top:=50, _
Width:=400, Height:=100)
myTextBox.TextFrame.TextRange.Text = "Arial Font Text Box"
myTextBox.TextFrame.TextRange.Font.Color = vbBlack
End With
End Sub

Suggestions?

John Wilson
08-01-2016, 09:04 AM
Your code is telling it to pick the first slide.


With ActivePresentation.Slides(1)

The current slide would be


ActiveWindow.Selection.SlideRange(1)

Also you are using legacy code from 2003 to set the font colour. It will work OK for something simple like black but will not let you apply e.g. line weight, reflections etc

The corrected code using the new TextFrame2 object


myTextBox.TextFrame2.TextRange.Font.Fill.Forecolor.RGB = vbBlack

nullpointer
08-01-2016, 09:08 AM
Perfect!

Thank You!