Objective
To add or modify title in a PowerPoint slide using VBA by user input box.
Approach
Here we have used two input boxes, which are used to get the data for title text. If the title is not present, then the title will be added. If the title is already present in the slide, then the title will be modified.
Steps
We have followed the below mentioned steps to add/modify the title in slide 1 –
- Add the command button and change its caption.
- Add the below shown code in the command button [using view code]
- We have used two input boxes to have the input for title i.e. (1) Financial Year (2) Quarter
- If title already exists, then change the title text according to requirement
- If title does not exist, then add the title with the required text
- We have also modified the font size of the title
For demonstration purpose we had a slide similar to one shown below.Here in the blue box you can see the sample slide title, where we have used Year 2018 as sample year , quarter 4 as a sample quarter for demonstration purpose.
Once we click on “Enter Details” button, one input box will pop up which will ask for entering financial year.We have entered 2019 as input.
After entering the financial year , another message box for “Quarter” will appear.We have entered 2 as input.
Now, if we look in the image below we can see that title text has been changed, earlier it had financial year as 2018 and quarter as 4. Now, it has financial year as 2019 and quarter as 2.
Code
Private Sub EnterDetails_Click() Dim Financial_Year As String Dim Quarter As String Dim MyTitle As Font Set MyTitle = ActivePresentation.Slides(1).Shapes.Title.TextFrame.TextRange.Font 'Get the input for using in slide title Financial_Year = InputBox("Enter the financial Year") Quarter = InputBox("Enter the Quarter") 'Check if title already exists in the slide or not If ActivePresentation.Slides(1).Shapes.HasTitle = msoTrue Then ActivePresentation.Slides(1).Shapes.Title.TextFrame.TextRange.Text = "Revenue in Year " & Financial_Year & " in Quarter " & Quarter Else 'Add the new title if it does not exist ActivePresentation.Slides(1).Shapes.AddTitle.TextFrame.TextRange.Text = "Revenue in Year " & Financial_Year & " in Quarter " & Quarter End If MyTitle.Size = 23 End Sub
Note
In case there were no title then this code will add a title.We can also adopt the approach mentioned above for sub title or for any other objects. We can also modify the properties of text, title etc.
Post you may like
Open the PowerPoint presentation from excel macro using VBA
1 comment on “Add or modify title in a PowerPoint slide using VBA by user input box”
Comments are closed.