InsertFromFile - question

M

Michael Yorke

Hi,

I've been playing with macros and want to create a simple macro to insert 1
slide from a file stored on our network. I'm using InsertFromFile to get the
file into my powerpoint presentation but what annoys me is having to specify
the index (where in my presentation I want the slide inserted). I'm used to
clicking and having the cursor in the place where I want my slides inserted.
Below is the text from the PowerPoint VB help regarding InsertFromFile

Inserts slides from a file into a presentation, at the specified location.
Returns an integer that represents the number of slides inserted.

expression.InsertFromFile(FileName, Index, SlideStart, SlideEnd)
expression Required. An expression that returns a Slides collection.

FileName Required String. The name of the file that contains the slides
you want to insert.

Index Required Long. The index number of the Slide object in the
specified Slides collection you want to insert the new slides after.

SlideStart Optional Long. The index number of the first Slide object in
the Slides collection in the file denoted by FileName.

SlideEnd Optional Long. The index number of the last Slide object in the
Slides collection in the file denoted by FileName.

Example
This example inserts slides three through six from C:\Ppt\Sales.ppt after
slide two in the active presentation.

ActivePresentation.Slides.InsertFromFile _
"c:\ppt\sales.ppt", 2, 3, 6

I don't want to specify and index. or use the current position of the
cursor. Is this possible please? even if it means writing more code to
capture the current position?

thanks very much
 
D

David M. Marcovitz

If you are running this in Normal view (not in the slide show), use this
code to get the current position:

ActiveWindow.Selection.SlideRange(1).SlideIndex

If you are running this in Slide Show view, use this code:

ActivePresentation.SlideShowWindow.View.Slide.SlideIndex

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/

=?Utf-8?B?TWljaGFlbCBZb3JrZQ==?=
 
S

Shyam Pillai

Hey Steve,
This is what I do:

' ------------- Snip -------------
If ActiveWindow.ViewType = ppViewSlideSorter Then
'Current cursor position is not retreived when selection is between
slides.
If ActiveWindow.Selection.Type = ppSelectionNone Then
'Switch to slide view and back.
ActiveWindow.ViewType = ppViewSlide
ActiveWindow.ViewType = ppViewSlideSorter

' This forces a selection based on the cursor position
' If cursor is between 2nd and 3rd slide it will select 2nd slide
' If cursor is before the 1st slide it will select the 1st slide
' If cursor is after the last slide it will select the last slide.
' If still nothing is selected then there are no slides in the
presentation.

If ActiveWindow.Selection.Type = ppSelectionSlides Then
Debug.Print ActiveWindow.Selection.SlideRange.SlideIndex
Else
Debug.Print "No slides in the presentation."
End If
Else
' Do the rest

End If
End If
' ------------- Snip -------------
--
Regards,
Shyam Pillai

Animation Carbon
http://www.animationcarbon.com
 
M

Michael Yorke

Thanks everyone for your comments and replies. its great to know there is a
solution to my question. Only problem I have now is actually getting it to
work. I'm a complete numpty when it comes to VB.

Shyam, your code looks good and kind of makes sense but I don't know where
to put in the actual bit regarding insetfilefrom.

Could someone be so king to post an amended version of Shyam's code with the
relevant bits it to get this to work. I'd be very grateful.

Thanks

Mike
 
M

Michael Yorke

Steve,

thanks. But I'm still not sure what I need to do to get the slides inserted
from an existing presentation. I can't see the InsertFromFile line in the
code you posted. Did I explain I'm a complete numpty when it comes to VB? I
don't know the difference between a sub routine and a function. I don't seem
to be able to run your code when I paste it into a new module.

I'm really not sure what I'm doing!

Mike
 

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