Using VBA to add slide and image (error when slide not selected)

K

Keith

I'm using the following code (Office 2003) to add the contents of the
clipboard to a new slide (saves me a few steps of adding a slide, pasting,
etc.). I'm using this to develop some basic training material with
screenshots of the target application.

However, in order for it to work, I not only have to have powerpoint active,
but actually click in the active document as well- otherwise, it throws an
error (runtime error '-2147188160 (80048240)' View (unknown member): Invalid
request Clipboard is empty or contains data that cannot be pasted here). It
appears that if the slide is selected in the left slides pane, it throws the
error, if the slide itself is active, it pastes just fine.

(1) Can anyone provide a modification to the code below that will
automatically select the active presentation in powerpoint if it isn't
already selected, so I can avoid this error?

(2) I have this code linked to a custom toolbar/button. When in any other
powerpoint presentation (other than my base template) I get a macro warning.
What is the preferred method of setting the template as an add-in (or
something like that) so the macro is always available regardless of what ppt
I have open, and only get the macro warning once when opening powerpoint the
first time?

Thanks!
Keith

'------------------------------------------------------------
Sub addslide()

Dim oView As View
With ActivePresentation.Slides
Set oView = ActiveWindow.View
oView.GotoSlide .Add(oView.Slide.SlideIndex + 1, _
ppLayoutTitleOnly).SlideIndex
Set oView = Nothing
End With
ActiveWindow.View.Paste

End Sub
 
S

Steve Rindsberg

Try this instead:

Sub addslide()

Dim oSld As Slide

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

End Sub


And as you've already guessed, turning your code into an add-in is the way to
go. Start reading hereabouts:

Creating and Installing Add-ins, Toolbars, Buttons
http://www.pptfaq.com/index.html#name_Creating_and_Installing_Add-ins-_Toolbars
-_Buttons_
 

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