Programming to the vbe

D

dave.cuthill

I played with it a little after I posted this and was able to create a
module. But I really need to be able to put something behind a slide to
be able to add some code to an activex scroll bar that it add with
code. How do you place code in a Powerpoint slide object?
 
S

Shyam Pillai

Dave,
You perfrom the same operations as Excel. One point to note is that a slide
object does not appear in the project explorer unless there is an activex
control on that slide. Once the control is on the slide, you can enumerate
it and insert code within that object's module.


' Assumes that a slide object exists with an activex control on it and the
1st object in the project
' explorer is that object.
Call ActivePresentation.VBProject.VBComponents(1).CodeModule.InsertLines(1,
"Option Explicit")
 
D

dave.cuthill

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.

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.

Sub InsertGraphicOnSlide()

Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppShape As PowerPoint.Shape
Dim ppCurrentSlide As PowerPoint.Slide

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


With ActivePresentation.VBProject.VBComponents(Slide1).CodeModule
.InsertLines 1, _
"Private Sub ScrollBar1_change()" & Chr(13) & _
"ScrollBar1.SmallChange = 1" & Chr(13) & _
"ScrollBar1.Max = 100" & Chr(13) & _
"ScrollBar1.Min = 0" & Chr(13) & _
"Ht = Shapes(""Graphic_1"").Height" & Chr(13) & _
"Increment = 77.04 + ((496.8 - (Ht + 77.04)) * ScrollBar1.Value /
ScrollBar1.Max)" & Chr(13) & _
"'increment = 48 + (-1.2762 * ScrollBar1.Value)" & Chr(13) & _
"ActivePresentation.SlideShowWindow.View.Slide.Shapes(""Graphic_1"").Top
= Increment" & Chr(13) & _
"End Sub"
End With

End Sub
 
D

dave.cuthill

You are correct that I know how to capture the desired picture file.
I'll play around with your suggestions but I did have one other
question that may help further (but I'm not really sure). How do you
determine what name Powerpoint gives to the picture file as it is
inserted. It almost seems as though it has a number of different names
depending on how you are manipulating it. If it is in the custom
animation area it seems to have the name that it was saved as and if
you try to manipulate it with vb is goes by "Picture X".

If rely on Powerpoint to name the picture how do I place this name in
the code module insertion area since it will vary or am I better to
preselect the name as I am now doing? If the user wanted to insert 2
pictures I would need to have the code use the name assigned by
Powerpoint so as not to confuse the scrollbar code or I guess I could
check for the existance of a picture and scrollbar combination prior to
inserting the next picture/scrollbar and then increment the name of the
scrollbar and the picture.

Thanks for your help so far.

David
 
D

dave.cuthill

Steve:

I am getting a user defined type not defined for Dim oScroll As
PowerPoint.ScrollBar do I need to register something to get this to
work?

David
 
D

dave.cuthill

I had it manually set in the references but was still getting the
message. Setting it to an object seems to work fine.

At least you seem to have a better idea where the walls and furniture
are located.

David
 
D

dave.cuthill

Okay so I think I now have it working the way I want it (still some
refinement needed) - but now when I try to save it as an addin I get a
message stating that it can't be saved. Initially it was giving me a
message about an activex item being on the slide which there wasn't and
now it just plain says it can't be saved as an addin with no
explanation.

Any ideas?

David
 
D

dave.cuthill

Thanks that did the trick - I had some code that I wasn't using that
wasn't compileable.

Thanks for all you help.

David
 
Top