PDA

View Full Version : Adding text to text boxes



sgini
01-03-2018, 04:28 AM
Hello,

I've never really used VBA before so this could be really simple for all I know, but I have created a on screen keyboard on powerpoint using action buttons, and would like to know how to add text to a text box when the corresponding key/action button is pressed, so pressing the "A" button puts A into the text box and so on, thanks!

ranman256
01-03-2018, 07:16 AM
Its a little hard doing it in Powerpoint since PPT is already setup for user to enter text into a text box. No programming needed.
VB (B for basic) is easy. To assign a text box normally it would be as simple as: txtBox1 = "My Text"

The hard part of the programming is text boxes may have random names. So vb doesnt know the name of the text box to assign the string,
but the user can just type in without knowing the name of the textbox.
I'll look into it some more.

ranman256
01-03-2018, 07:32 AM
a lot of work to do what PPT does without code.
IF, the shapes are there.



sub btnAdd_Click()
Dim sld As Slide
Set sld = Application.ActiveWindow.View.Slide


vRet =inputbox( "Enter Text","Add")
sld.Shapes(1).TextFrame.TextRange.Text = vRet


set sld = nothing
end sub

John Wilson
01-03-2018, 08:42 AM
Set up the "keyboard" with a letter on each and SPACE on the space bar.

ALL of the keys should run this code.


Sub AddText(oshp As Shape)
Dim strKey As String
Dim osld As Slide
strKey = oshp.TextFrame.TextRange
If strKey = "SPACE" Then strKey = " "
Set osld = SlideShowWindows(1).View.Slide
With osld.Shapes("Title 1") 'change the name
.TextFrame.TextRange = .TextFrame.TextRange & strKey
End With
End Sub

21284

NOTE it will only work in show mode and you might have to change the name of the shape to show the text.

sgini
01-04-2018, 06:48 AM
Managed to incorporate all that code onto my keyboard and it does the job, thanks!