Finding the type of the active slide

M

Michael

Hi - I'm trying to write what I thought would be simple code to insert one
or more selected images into the active slide.

It worked fine unless the View | Master | Slide was selected, in which case
the error "sliderange cannot be constructed from master" occurs.

OK - so I tried to get the view so I could code the image insertion
accordingly.

Trouble is, even with View | Master | Slide selected, the view is still
returned as ppViewNormal!

I've tried to find other ways of finding what the active slide/view is - but
cannot find a way.

Help!!!

Here is my code . . .


Sub InsertImage()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vSelectedItem As Variant
Dim sNetworkImagePath As String
Dim sFolderPath As String
Dim iCnt As Integer
On Error GoTo ErrorHandler
PowerPoint.Application.Visible = msoTrue
iCnt = 0

If Dir(sNetworkMyPicturesPath, vbDirectory) <> "" Then
sFolderPath = sNetworkMyPicturesPath & "_Rabobank Image Library.lnk"

ElseIf Dir(sLocalImagePath, vbDirectory) <> "" Then
sFolderPath = sLocalImagePath

Else
sFolderPath = sLocalBasePath & GetUser & "\My Documents\"

End If

With fd
.InitialFileName = sFolderPath

If .Show Then
'user clicked OK or dbl-clicked image
'Step through each item in FileDialogSelectedItems collection
For Each vSelectedItem In .SelectedItems
MsgBox ActivePresentation.Windows.Count
Call ShowView
sNetworkImagePath = CStr(vSelectedItem)

If sNetworkImagePath <> "" Then
'determine the view

If ActivePresentation.Windows(1).ViewType = ppViewNormal
Then
'Slide View
With ActiveWindow.Selection.SlideRange.Shapes
.AddPicture(FileName:=sNetworkImagePath, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=10 + iCnt, Top:=10 + iCnt).Select
End With

ElseIf ActivePresentation.Windows(1).ViewType =
ppViewTitleMaster Then

'Title Master View
With ActivePresentation.TitleMaster.Shapes
.AddPicture(FileName:=sNetworkImagePath, _
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue,
_
Left:=10 + iCnt, Top:=10 + iCnt).Select
End With

ElseIf ActivePresentation.Windows(1).ViewType =
ppViewSlideMaster Then

'Title Master View"
With ActivePresentation.SlideMaster.Shapes
.AddPicture(FileName:=sNetworkImagePath, _
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue,
_
Left:=10 + iCnt, Top:=10 + iCnt).Select
End With

Else
MsgBox "You cannot add images in this view.", _
vbOKOnly + vbInformation, sMsgBoxH

End If

End If
iCnt = iCnt + 10
Next vSelectedItem

Else
'do nothing
End If
End With
Set fd = Nothing

Exit Sub

ErrorHandler:
MsgBox Err.Number & vbCr & vbCr & Err.Description, _
vbOKOnly + vbExclamation, sMsgBoxH

End Sub
 
S

Shyam Pillai

Michael,
When the normal view is active, the view of the 2nd pane should be used to
ascertain if it is a slide or slidemaster.


If ActiveWindow.ViewType = ppViewNormal Then
Select Case ActiveWindow.Panes(2).ViewType

Case ppViewSlide

Case ppViewSlideMaster

Case Else

End Select
End If


--
Regards,
Shyam Pillai

Animation Carbon: http://skp.mvps.org/ac/
 

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