Vba code to replace and position text box in PowerPoint

shoun2502

New Member
Joined
Nov 14, 2018
Messages
43
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Dear All,

The code above replace my font Size and Apart from this I need to align to the below mentioned position . Please help me to incorporate this code

Code:
Sub changeFont()
For Each aSlide In ActivePresentation.Slides
For Each aShape In aSlide.Shapes
If aShape.Type = msoTextBox Then
If aShape.TextFrame.HasText Then
If aShape.TextFrame.TextRange.Font.Name = "Franklin Gothic Demi" Then
If aShape.TextFrame.TextRange.Font.Size = 40 Then
      aShape.TextFrame.TextRange.Font.Size = Replace(aShape.TextFrame.TextRange.Font.Size, 40, 25)
End If
End If
End If


End If
Next
Next
End Sub

The code above replace my font Size and Apart from this I need to align to the below mentioned position . Please help me to incorporate this code


.Top=23
.Left=44
.Height=44


Thanks in anticipation.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Re: Vba code to replace and position text box in powerpoint

Code:
'      [COLOR=#ff0000] try replacing this line[/COLOR]
      aShape.TextFrame.TextRange.Font.Size = Replace(aShape.TextFrame.TextRange.Font.Size, 40, 25)
'       [COLOR=#ff0000]with these lines[/COLOR]
        With aShape
            .TextFrame.TextRange.Font.Size = Replace(aShape.TextFrame.TextRange.Font.Size, 40, 25)
            .Top = 23
            .Left = 44
            .Height = 44
        End With
End Sub
 
Upvote 0
Re: Vba code to replace and position text box in powerpoint

Thanks for the reply. It works very well . Actually in some of my Text placeholder there is some additional spaces that is not being deleted to the left AND right of my TEXT.

I want my TEXT inside textholder to be autofit without any spaces.

I am trying to use the below code but it doesn't work . Please help with that.

Sub changeFont()
For Each aSlide In ActivePresentation.Slides
For Each aShape In aSlide.Shapes
If aShape.Type = msoTextBox Then
If aShape.TextFrame.HasText Then
If aShape.TextFrame.TextRange.Font.Name = "Franklin Gothic Demi" Then
If aShape.TextFrame.TextRange.Font.Size = 10 Then
With aShape
.TextFrame.TextRange.Font.Size = Replace(aShape.TextFrame.TextRange.Font.Size, 10, 25)
.Top = 23
.Left = 44
.Height = 44
.WordWrap = True
End With


End If
End If
End If


End If
Next
Next
End Sub

It would be grateful if you could please help with that.
 
Last edited:
Upvote 0
Re: Vba code to replace and position text box in powerpoint

Actually in some of my Text placeholder there is some additional spaces that is not being deleted to the left AND right of my TEXT
Code:
aShape.TextFrame.TextRange.Text = Trim(aShape.TextFrame.TextRange.Text)


same code, avoiding repetition
Code:
With aShape.TextFrame.TextRange
    .Text = Trim(.Text)
End With
 
Last edited:
Upvote 0
Re: Vba code to replace and position text box in powerpoint

Hi Yongle ,

The mentioned code is not working . It would be grateful if you could please share any other subroutine for that.
 
Upvote 0
Re: Vba code to replace and position text box in powerpoint

The code works for me
Post your amended code so that I can establish why it does not work for you.
Thanks
 
Upvote 0
Re: Vba code to replace and position text box in powerpoint

Hi Yongle

I am currently using this code to establish . However what I have just discovered that some of the text in text placeholder has some indentation which should be

Before text = 0 cm
Special = None
Alignment = Left


Sub changeFont()
For Each aSlide In ActivePresentation.Slides
For Each aShape In aSlide.Shapes
If aShape.Type = msoTextBox Then
If aShape.TextFrame.HasText Then
If aShape.TextFrame.TextRange.Font.Name = "Franklin Gothic Demi" Then
If aShape.TextFrame.TextRange.Font.Size = 10 Then
With aShape
.TextFrame.TextRange.Font.Size = Replace(aShape.TextFrame.TextRange.Font.Size, 10, 25)
With aShape.TextFrame.TextRange
.Text = Trim(.Text)
End With

.Top = 23
.Left = 44
.Height = 44


End With


End If
End If
End If


End If
Next
Next
End Sub


Please help me to incorporate the same in this subroutine to establish the same.
 
Last edited:
Upvote 0
Re: Vba code to replace and position text box in powerpoint

1. You asked for
"Vba code to replace and position text box in powerpoint" - which i provided


2. Next you ask
"actually in some of my Text placeholder there is some additional spaces that is not being deleted to the left AND right of my TEXT" - which I provided
3. Now you ask
"however what I have just discovered that some of the text in text placeholder has some indentation which should be Before text = 0 cm, Special = None, Alignment = Left"

Suggest you start a new thread for latest request - I am busy and perhaps someone else will look at a new thread
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,287
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top