Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2023, 01:59 PM
msnyder701 msnyder701 is offline VBA needed for changing all text boxes in presentation Windows 10 VBA needed for changing all text boxes in presentation Office 2021
Novice
VBA needed for changing all text boxes in presentation
 
Join Date: Jul 2023
Posts: 2
msnyder701 is on a distinguished road
Default VBA needed for changing all text boxes in presentation

I have this code for changing the location of a single text box:
Sub Macro2(control As IRibbonControl)
Dim oShp As Shape
On Error Resume Next

Set oShp = ActiveWindow.Selection.ShapeRange(1)

With oShp
.LockAspectRatio = False
.Left = 34.5
.Top = 84.5
End With



End Sub

What I want to do is to do this for all text boxes that contain text (i.e., not shapes that are charts, pictures, etc.) in the entire presentation. Can someone show me how to do this? The codes that I've tried to write just don't work. Thanks!
Reply With Quote
  #2  
Old 07-19-2023, 07:55 PM
excelledsoftware excelledsoftware is offline VBA needed for changing all text boxes in presentation Windows 10 VBA needed for changing all text boxes in presentation Office 2007
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

You have a great start. Now you need to go through each shape in each slide in the presentation. There are a few more objects to do this.
Code:
Sub Macro2(control as IRibbonControl)
  Dim oShp As Shape, oSld As Slide, pst As Presentation, pass As Integer
  'On Error Resume Next dont like these, I suggest not to use it without handling

  'set the variables
  Set pst = ActivePresentation
  
  'start the loops
  For Each oSld In pst.Slides
    For Each oShp In oSld.Shapes
      pass = 1
      'check if we want to skip the shape
      If oShp.HasTextFrame = msoFalse Then pass = 0
      'we can add as many as we want here in case there is more criteria needed
      If pass = 1 Then
        With oShp
          .LockAspectRatio = False
          .Left = 34.5
          .Top = 84.5
        End With
      End If
    Next oShp
  Next oSld
End Sub
If this tries to move charts or other items we will just check for oShp.type and make sure its the type that you want.
Let me know if you have any other questions.

Thanks
Reply With Quote
  #3  
Old 07-20-2023, 07:00 AM
JohnWilson JohnWilson is offline VBA needed for changing all text boxes in presentation Windows 10 VBA needed for changing all text boxes in presentation Office 2019
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,912
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

What is the reason for using (control as IRibbonControl) ?

When you say TextBox do you mean TextBoxes (From Insert TextBox) or Placeholders that may or may not contain text? The code would be quite different.
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #4  
Old 07-20-2023, 12:57 PM
msnyder701 msnyder701 is offline VBA needed for changing all text boxes in presentation Windows 10 VBA needed for changing all text boxes in presentation Office 2021
Novice
VBA needed for changing all text boxes in presentation
 
Join Date: Jul 2023
Posts: 2
msnyder701 is on a distinguished road
Default

@excelledsoftware: Thank you so much! This will do the trick, I think.

@JohnWilson: The reason for the (control as IRibbonControl) is that ultimately I'm going to make this an add-in after I get the macro itself working correctly. As to your other question, I haven't yet decided whether I want it to work from Insert Textbox or from placeholder; I'll get to that in a bit.

Thanks again to both of you!
Reply With Quote
  #5  
Old 11-11-2023, 12:32 AM
laith93 laith93 is offline VBA needed for changing all text boxes in presentation Windows 10 VBA needed for changing all text boxes in presentation Office 2019
Competent Performer
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by excelledsoftware View Post
Now you need to go through each shape in each slide in the presentation. There are a few more objects to do this.
Dear,
The majority of my slides have text box for a title and text box for body text, by using this code, it will change the dimension of all text boxes including title textbox, which causes disorganization or interference of slide elements, as in screenshot
69.png
so how to apply this code to text boxes that contain body text only?
Thanks
Reply With Quote
Reply

Tags
select all, text boxes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed in changing text & line colour please dazzystar Word 2 05-27-2021 09:39 AM
VBA needed for changing all text boxes in presentation Changing the names of text boxes catflap Word 20 05-11-2018 08:57 AM
Changing the font colour in all text boxes marqives Word VBA 1 11-25-2014 06:05 PM
VBA needed for changing all text boxes in presentation Changing the placeholder text for drop down boxes DeadBatteries Word 1 08-24-2012 09:09 AM
Quick change for all text boxes in a presentation tmlander PowerPoint 1 03-09-2012 01:20 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:15 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft