# Vba code to replace and position text box in PowerPoint



## shoun2502 (Jun 28, 2019)

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 


```
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.


----------



## Yongle (Jun 28, 2019)

*Re: Vba code to replace and position text box in powerpoint*


```
'      [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
```


----------



## shoun2502 (Jun 28, 2019)

*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
> ...



It would be grateful if you could please help with that.


----------



## Yongle (Jun 28, 2019)

*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




```
aShape.TextFrame.TextRange.Text = Trim(aShape.TextFrame.TextRange.Text)
```


same code, avoiding repetition

```
With aShape.TextFrame.TextRange
    .Text = Trim(.Text)
End With
```


----------



## shoun2502 (Jun 28, 2019)

*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.


----------



## Yongle (Jun 28, 2019)

*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


----------



## shoun2502 (Jun 29, 2019)

*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.


----------



## Yongle (Jun 29, 2019)

*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 b_e *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


----------

