disappearing text on mouse click in text box in powerpoint using vba - vba

I am facing an issue with the custom textbox in a PowerPoint 2010 slide. I want to make the text that is initially there inside the textbox (say "Click to enter text") to disappear as soon as mouse is clicked on the textbox to enter some text. If this is possible through events in VBA, I would like to know which event(associated with the textbox) to capture and how to do it using VBA?
Also changing the height parameter is not having any effect in PowerPoint 2010.
here is my code that defines the textbox :
Dim sld As Slide
Set pShape = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=50, Top:=50, width:=500, Height:=300)
pShape.TextFrame.TextRange = "Click to enter text"
pShape.TextFrame.TextRange.Font.Size = 14
pShape.Line.Visible = True
pShape.Line.ForeColor.RGB = RGB(0, 0, 0)
pShape.Line.DashStyle = msoLineDash
Plz help me out with this..
Thanks in advance!!!

The height is not taking because the default is to resize to fit availabl text.
Either use a shape not a textbox or reset the defaut
Set pShape = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=50, Top:=50, Width:=500, Height:=300)
pShape.TextFrame.AutoSize = ppAutoSizeNone
pShape.Height = 300
Making the text disappear on click is possible but difficult. You can use the WindowSelectionChange event but this is very difficult to set up if you are not writing an addin. You would need to write a WithEvents Class module and initialise an instance. Fairly advanced!

Related

PowerPoint Add-in Add a textbox to a selected slide

I'm trying to make a button that when clicked, will add two text boxes to the selected slide in a specified place with specified formatting (font, size, color, justified). I've been trying to reverse engineer anything applicable, but just end up breaking things. This set of code will allow me to make a rectangle (not a textbox which is preferred) size it and place it (just 1 not 2) with sample text.. For the life of me I cant figure out how to make it create a textbox on the selected slide or active window.. what am I doing wrong? Heres the code I found..
Sub AddTextBox()
Set myDocument = ActivePresentation.Slides(1)
With myDocument.Shapes _
.AddTextBox(msoShapeRectangle, 180, 175, 350, 140).TextFrame
.TextRange.Text = "Ctrl+A(Select all), Ctrl+V(Paste)"
.MarginTop = 10
End With
End Sub
To refer to the slide that's currently being displayed, you can use the Slide Property of the View object...
Dim mySlide As Slide
Set mySlide = ActiveWindow.View.Slide
For creating a textbox, here's the proper syntax as per the documentation here...
Syntax
expression. AddTextbox( Orientation, Left, Top, Width,
Height )
expression A variable that represents a Shapes object.
So, in your case, it would be something like this...
Dim myTextbox As Shape
Set myTextbox = mySlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 180, 175, 350, 140)
Change the text orientation as desired.

Edit Form Control Label Caption on VBA

Trying to edit the text of a form control label named lblsearchreminder and make sure that the font is Arial and size 20. I am pulling the edited text from an ActiveX textbox1 and trying to make that the caption of the label. If anyone has any insight I would greatly appreciate it.
Sub btnAltCustomSearch_Click()
Dim strTextBox As String
If Worksheets("User Interface").OLEObjects("TextBox1").Object.Value = "" Then
ErrorX.Show
Else
strTextBox = Worksheets("User Interface").OLEObjects("TextBox1").Object.Value
Worksheets("Muscle Wasting Database").Shapes("lblsearchreminder") = vbCrLf & "Disease: All" & vbCrLf & vbCrLf & "Keyword: " & strTextBox
lblsearchreminder.Object.Characters.Text = "Arial"
lblsearchreminder.Object.Font.Size = 20
End If
End Sub
Yes the textbox1 is an ActiveX textbox control, but I will ideally use a Form Control label. So I am trying to pull the typing from the ActiveX textbox and use it in the Form Control label – Thor Nagel 3 hours ago
Unfortunately you can't manipulate the font-size/name, color or style of a Form Control Label. If you notice the formatting items have been "grayed out" in the Font group on the Excel Ribbon.
To set a Text is easy
Dim lblsearchreminder As Shape
Set lblsearchreminder = Sheet1.Shapes("Label 1")
lblsearchreminder.TextFrame.Characters.Text = "Hello"
But you cannot do (Even though Intellisense allows it)
lblsearchreminder.TextFrame.Characters.Font.Name = "Arial"
or
lblsearchreminder.TextFrame2.TextRange.Characters.Font.Name = "Arial"
I would recommend using a TextBox shape or an ActiveX Label instead.
Similarly you cannot change the font using
lblsearchreminder.TextFrame.Characters.Font.Size= 20
I don't think you're using a Form Control. TextBox1 would be the default name for an ActiveX control, which would be coherent with using .OLEObject.Object to retrieve it.
Declare a MSForms.TextBox variable for it.
Dim box As MSForms.TextBox
Now assign it to the .OLEObject.Object:
Set box = Worksheets("User Interface").OLEObjects("TextBox1").Object
If the sheet "User Interface" exists in ThisWorkbook at compile-time, give it a code name (F4; set the (Name) property to e.g. UserInterfaceSheet) - then you can use that identifier directly, without needing to pull the worksheet from the Worksheets collection:
Set box = UserInterfaceSheet.OLEObjects("TextBox1").Object
Now you have an early-bound object reference to play with, you'll have IntelliSense to guide you. MSForms.TextBox does not have a .Characters property. It does have a .Font property though, so you can start exploring that:
So the Font property is an object of type NewFont; using the Object Browser (F2) you can browse its members:
Thus:
box.Font.Name = "Arial"
box.Font.Size = 20
Should do it.
Watch out for misleading names and prefixes: lblsearchreminder reads like you're looking at a MSForms.Label control, not a TextBox. txtSearchReminder would be more appropriate, or if you prefer control-agnostic names, SearchReminderBox works as well.
Also Error is a function from the VBA.Conversion module, that you are shadowing here.

Change colour of highlighted text of a textbox in PowerPoint VBA

So I want to have a button that changes the selected/highlighted text of a TextBox in PowerPoint VBA.
I know how to change all the text on a TextBox, but not the selected/highlighted.
Thanks for reading.
You'd want to ensure that there's a current selection and that the selection is text before trying to change anything:
With ActiveWindow.Selection
If .Type = ppSelectionText Then ' Text is selected
' Make it green, for example:
.TextRange.Font.Color.RGB = RGB(0, 255, 0)
End If
End With

How to set Color for the text box in visual basic Word macro

I tried to change background color of text box.
These are not working:
Me.TextBox1.ForeColor = &HFF&
Me.TextBox1.BackColor = &H8000000D
I did not find any field corresponding to color. My text box:
Set Box = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=50, Top:=50, Width:=440, Height:=300)
Box.WrapFormat.Type = wdWrapSquare
You are not having any success with the color for your text box possibly for two reasons.
Firstly, you create your text box correctly using the shapes object but then you when you set the colour you use Me.TextBox1. Since you have created the object using the Box variable it is better to use this variable to set the colour.
The second problem is that the Shape object uses the Fill property to set the colour. Therefore you simply need to use the following code after creating the Box:
Box.Fill.ForeColor = &HFF&
Box.Fill.BackColor = &H8000000D

Entering information into the Notes section of a PowerPoint slide using VBA

I am trying to find out how you write VBA to enter a text box into a slide, and enter text. I am also trying to find vba for entering text into the notes section of a PowerPoint slide.
Any help would be greatly appreciated. I have tried to find a site specifically for this, but have not been able to do so
Entering text into a PPT slide is about the same as entering into the notes section.
You have to start out with a Slide object reference, which represents the slide you're adding to; and you add a text box shape to the slides' shapes collection.
Example:
Sub AddTextBoxToSlide()
Dim oDestSlide As PowerPoint.Slide
Set oDestSlide = ActivePresentation.Slides(1)
Dim slideWidth As Single
Dim slideHeight As Single
slideWidth = oDestSlide.Parent.PageSetup.SlideWidth
slideHeight = oDestSlide.Parent.PageSetup.SlideHeight
Dim oTextBox As PowerPoint.Shape
Set oTextBox = oDestSlide.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=0, _
Top:=0, _
Width:=slideWidth, _
Height:=slideHeight / 12)
oTextBox.TextFrame.TextRange.Text = "Shape text here"
End Sub
All this does is adds a text box shape to the first slide in the active presentation at the top of the slide. It is as wide as the slide and 1/12th the height of the slide. The parameters for Shapes.AddTextbox() are pretty self-explanatory...
To add to the notes section, I just use the NotesPage object on the slide your notes page is in...so the above code would be about the same, except:
Set oTextBox = DestSlide.NotesPage.Shapes.AddTextbox(msoTextOrientat...
This is an old question, but since you can't record macros in PowerPoint, people will be searching for questions like this until you can.
I didn't need this for adding text to slides, but I tried it for adding text to Notes. However, in Outline View, nothing appeared in my Notes section. It wasn't until I went to View-->Notes Page, and I saw the message I'd added -- at the top of the screen.
You see, when you change Set oTextBox = oDestSlide.Shapes to Set oTextBox = oDestSlide.NotesPage.Shapes, you're not adding text to the Notes. You're adding a textbox to the notes. And that textbox appears only in Notes Page view (at the top of the screen, until you move it).
What we really want to do is add our text to Placeholder 2 (the notes area) on the notes page, like this:
oDestSlide.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.InsertAfter "Notes text here"