PDA

View Full Version : Add Text to different slides



Nicolaf
08-10-2016, 10:23 AM
Hi,

I have some code which adds text "NEW" to a specific slide eg. slide 2.

I would now like to amend code so that this same text ("NEW") is added to two or more slides (eg. slides 1,2 and 3).

How can I amend code to do this?

Below code for text added to 1 slide (ie. slide2).


Sub Textboxnew()
Dim myTextBox As Shape
With ActivePresentation.Slides(1)
Set myTextBox = .Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, Left:=450, Top:=20, _
Width:=100, Height:=100)
myTextBox.TextFrame.TextRange.Text = "NEW"
myTextBox.TextFrame.TextRange.Font.Color.RGB = vbRed
myTextBox.TextFrame.TextRange.Font.Size = 20
End With
End Sub


Thanks,
Nic

:think::think:

John Wilson
08-10-2016, 01:12 PM
Here are two different ways

The first adds to 1,2,3 the second only to selected slides


Sub Textboxnew()
Dim myTextBox As Shape
Dim mySld As Long
On Error Resume Next
'add to slide 1,2,3 change as required
For mySld = 1 To 3
With ActivePresentation.Slides(mySld)
Set myTextBox = .Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, Left:=450, Top:=20, _
Width:=100, Height:=100)
myTextBox.TextFrame.TextRange.Text = "NEW"
myTextBox.TextFrame.TextRange.Font.Color.RGB = vbRed
myTextBox.TextFrame.TextRange.Font.Size = 20
End With
Next mySld
End Sub


Sub Textboxnew_Sel()

'adds only to selected slides
Dim myTextBox As Shape
Dim osld As Slide
Dim osldRng As SlideRange
On Error Resume Next
Set osldRng = ActiveWindow.Selection.SlideRange
For Each osld In osldRng
Set myTextBox = osld.Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, Left:=450, Top:=20, _
Width:=100, Height:=100)
myTextBox.TextFrame.TextRange.Text = "NEW"
myTextBox.TextFrame.TextRange.Font.Color.RGB = vbRed
myTextBox.TextFrame.TextRange.Font.Size = 20
Next osld
End Sub

Nicolaf
08-11-2016, 01:27 AM
Thanks John,

So if I wanted to add text to slides 2,4 and 6 where would I put this the code below?


Sub Textboxnew_Sel()

'adds only to selected slides
Dim myTextBox As Shape
Dim osld As Slide
Dim osldRng As SlideRange
On Error Resume Next
Set osldRng = ActiveWindow.Selection.SlideRange
For Each osld In osldRng
Set myTextBox = osld.Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, Left:=450, Top:=20, _
Width:=100, Height:=100)
myTextBox.TextFrame.TextRange.Text = "NEW"
myTextBox.TextFrame.TextRange.Font.Color.RGB = vbRed
myTextBox.TextFrame.TextRange.Font.Size = 20
Next osld
End Sub

Thanks,
Nic

John Wilson
08-11-2016, 01:49 AM
Select slides 2,4,6 (hold down CTRL)
Copy the code

Open the vba editor ALT f11
Insert module Paste in the code
f5 to run OR go back to normal view View > Macro > Run

Nicolaf
08-11-2016, 01:52 AM
great thanks!

Nic

:hi::yes