I am using code to insert a picture, then a scroll bar - I then want to
be able to place code in the slide for the scroll bar change and scroll
events. The scroll bar value then controls the top position of the
added picture.
I sort of figured out crude way to do this but it am open to any
suggestions.
Thanks for filling in the background ... and I see you've already seen Shyam's
post.
Here is what I have so far. This is all "hard coded" - ultimately I
want it to prompt for a file name and then place the picture and
scrollbar on the active slide and then place the code in the active
slide to control the scrollbar.
Getting the filename from the user shouldn't be a problem for you, is that
correct?
A couple of suggestions, though:
Sub InsertGraphicOnSlide()
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppShape As PowerPoint.Shape
Dim ppCurrentSlide As PowerPoint.Slide
It's cleaner if you don't .Select anything so create a var to hold an object
reference to your scrollbar
Dim oScroll as PowerPoint.Scrollbar
Set ppApp = CreateObject("PowerPoint.Application")
ppApp.Visible = True
'Set ppPres = ppApp.Presentations.Add(msoTrue)
'Set ppCurrentSlide = ppPres.Slides.Add(Index:=1, _
Layout:=ppLayoutBlank)
'Set ppCurrentSlide = ActiveWindow.Selection.SlideRange
With ActiveWindow.Selection.SlideRange.Shapes
Set opicture = .AddPicture("c:\Picture1.png", _
msoFalse, msoTrue, 0, 0, 1, 1)
opicture.ScaleHeight 1, msoTrue
opicture.ScaleWidth 1, msoTrue
opicture.Name = "Graphic_1"
End With
ActiveWindow.Selection.SlideRange.Shapes.AddOLEObject _
(Left:=618#, Top:=156#, Width:=12#, Height:=294#,
ClassName:="Forms.ScrollBar.1", Link:=msoFalse).Select
' Get a reference to the shape as you create it rather than selecting it
Set oScroll =ActiveWindow.Selection.SlideRange.Shapes.AddOLEObject _
(Left:=618#, Top:=156#, Width:=12#, Height:=294#,
ClassName:="Forms.ScrollBar.1", Link:=msoFalse)
' I think you could use oScroll.Name here in place of ScrollBar1
' and simplify the code by having it output eg
With ScrollBar1
.SmallChange =
.Max =
.Etc
End With
I think that you could also use:
With Me.Shapes("Graphic_1")
' or even Me.Shapes.oPicture.Name if you want to generalize it further
.Top
.etc
End With