Adding comments to pasted slide with VBA

K

Keith R

I'm adapting some existing code, because I need to be able to make a few
notes to myself when using this macro to paste screenshots while developing
training material (to keep track of what user actions occurred right before
the screen shot, etc.). I've tried to edit it to allow the user to input
some text and paste it into the slide that was just pasted in, but it isn't
working- I get a runtime error that "selection (unknown member): invalid
request. Nothing appropriate is selected"

Can anyone help me with the syntax?
Many thanks,
Keith

Sub addslide()

Dim oSld As Slide

With ActivePresentation.Slides

Set oSld = ActiveWindow.Selection.SlideRange(1)
With .Add(oSld.SlideIndex + 1, ppLayoutTitleOnly)
.Shapes.Paste

TempComment = InputBox ("Enter your slide comments:", "Comments")
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select '*** this
is the line it stops on
With ActiveWindow.Selection.TextRange
.Text = TempComment
End With

End With
End With


End Sub
 
S

Steve Rindsberg

I'm adapting some existing code, because I need to be able to make a few
notes to myself when using this macro to paste screenshots while developing
training material (to keep track of what user actions occurred right before
the screen shot, etc.). I've tried to edit it to allow the user to input
some text and paste it into the slide that was just pasted in, but it isn't
working- I get a runtime error that "selection (unknown member): invalid
request. Nothing appropriate is selected"

Can anyone help me with the syntax?
Many thanks,
Keith

Try it like so

Sub addslide()

Dim oSld As Slide
Dim oShp As Shape
Dim TempComment As String

With ActivePresentation.Slides

Set oSld = ActiveWindow.Selection.SlideRange(1)
Set oShp = .Add(oSld.SlideIndex + 1, ppLayoutTitleOnly).Shapes.Paste(1)

TempComment = InputBox("Enter your slide comments:", "Comments")

oShp.TextFrame.TextRange.Text = TempComment

Set oSld = Nothing
Set oShp = Nothing

End With

End Sub
 
K

Keith R

On the line marked below, I get a "runtime error (unknown member): invalid
request. This type of shape cannot have a TextRange"
I'm using PP2003 on WinXP, if that helps. I open the .ppt with this code, do
a screenshot, then activate the code by clicking on a toolbar button that is
linked to the macro.

Steve, I'm not familiar with the PP object model; is the code below intended
to add the text to the actual comments field of the slide, or to add a new
shape to the slide itself (and add text)? I looked to see if I could find
any other shapes being added to the slide, but I wasn't able to find
anything other than the default empty title box behind the screenshot. My
preference would be to add the comments to the comment field rather than on
the slide itself, but honestly, I'll be pleased with anything I can get :)

Thanks!
Keith
 
S

Steve Rindsberg

On the line marked below, I get a "runtime error (unknown member): invalid
request. This type of shape cannot have a TextRange"
I'm using PP2003 on WinXP, if that helps. I open the .ppt with this code, do
a screenshot, then activate the code by clicking on a toolbar button that is
linked to the macro.

Steve, I'm not familiar with the PP object model; is the code below intended
to add the text to the actual comments field of the slide, or to add a new
shape to the slide itself (and add text)?

It pastes in whatever's on the clipboard, which creates a new shape. Not all
shapes can hold text (ie, "have a TextRange" per your error code) so the result
would depend on what's on the clipboard.

Try this instead ... it adds a text box in addition to doing the paste.
I'm not sure what you mean by the comment field ... Notes text, maybe? The
text in the pane beneath the slide itself? This version will also append your
comment text to whatever's there.

Sub addslide()

Dim oSld As Slide
Dim oShp As Shape
Dim TempComment As String

With ActivePresentation.Slides
' add a new slide
Set oSld = .Add(ActiveWindow.Selection.SlideRange(1).SlideIndex + 1,
ppLayoutTitleOnly)

With oSld
' do the paste
Set oShp = .Shapes.Paste(1)
' add a new shape to hold comment text
' this adds a rectangle in upper left corner, 4" wide by 2" deep
' measurements in points at 72 per inch
Set oShp = oSld.Shapes.AddShape(msoShapeRectangle, 0, 0, 288, 144)
TempComment = InputBox("Enter your slide comments:", "Comments")
oShp.TextFrame.TextRange.Text = TempComment

' to add the comment to notes text, this will work most of the time
' though not 100% reliable:
With .NotesPage.Shapes("Rectangle 3").TextFrame.TextRange
.Text = .Text & vbCrLf & TempComment
End With

End With

Set oSld = Nothing
Set oShp = Nothing

End With

End Sub


I looked to see if I could find
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top