PDA

View Full Version : how to paste text into a specific shape in presentation mode



pptSam
09-22-2010, 07:29 AM
Hello everybody
I'm back with a problem: I have written a code that copies the text from a shape into a variable when I click on that shape (in presentation mode). So that works.

Then the Code navigates to a specific slide (taht also works). There the text from the variable should be automaticaly pasted into another shape (without me clicking on it).

I know the name of the target-shape but still I don't know how to paste the text into this shape.

I would be very happy, if anybody could give me advice on this matter.

Thank you very much

John Wilson
09-23-2010, 03:42 AM
Assuming say the target slide is 6 and the shape is called "myshape" and the text is in strVar

Dim osld As Slide

SlideShowWindows(1).View.GotoSlide (6)
Set osld = SlideShowWindows(1).View.Slide
osld.Shapes("myshape").TextFrame.TextRange = strVar

pptSam
09-23-2010, 04:35 AM
Hello John
Your solution works perfect - thank you very much!

just for those who might be interested in this, I include all of my (now working) code:


Sub GoPutTxt(oshp As Shape)
On Error GoTo Err_slide2
'this sub copies the text from a shape that is clickt on to the variable stxt
'and shows this text in a msgbox
Dim oshp2 As Shape
Set oshp2 = oshp
stxt = oshp2.TextFrame.TextRange.Text
MsgBox stxt

'then the script jumps to the slide with the ID 258 (here in my example)
Dim Psld As Slide
Set Psld = Application.ActivePresentation.Slides.FindBySlideID(258)

With SlideShowWindows(1).View
.GoToSlide Psld.SlideIndex
End With
'then, it pasts the text into the shape with the name "Rectangle 3" (here in
'my case)

Psld.Shapes("Rectangle 3").TextFrame.TextRange = stxt

Exit_slide2:
Exit Sub

Err_slide2:
MsgBox Err.Description
GoTo Exit_slide2

End Sub

John Wilson
09-23-2010, 05:35 AM
Looks good, you could shorten the code a little. You do not need to set oshp2=oshp and the With - End With do not add anything in this instance

Sub GoPutTxt(oshp As Shape)
On Error GoTo Err_slide2
'this sub copies the text from a shape that is clickt on to the variable stxt
'and shows this text in a msgbox

stxt = oshp.TextFrame.TextRange.Text
MsgBox stxt

'then the script jumps to the slide with the ID 258 (here in my example)
Dim Psld As Slide
Set Psld = Application.ActivePresentation.Slides.FindBySlideID(258)

SlideShowWindows(1).View.GotoSlide Psld.SlideIndex

'then, it pasts the text into the shape with the name "Rectangle 3" (here in
'my case)

Psld.Shapes("Rectangle 3").TextFrame.TextRange = stxt

Exit_slide2:
Exit Sub

Err_slide2:
MsgBox Err.Description
GoTo Exit_slide2

End Sub