Adjust Object Position with VBA

R

Rob

Is it ossible to actually have an object move with VBA?

I have a timeline and a today bar that I manually have to move every morning
and if I can automate this action it would be awesome.

I'v tried to capture it via recording a macro and then tweaking that but it
keeps giving me errors.


Thanks In Advance!
 
D

David Marcovitz

Yes, this is possible. You first need a way to identify the object: by
selection (Normal View only), name, number, tag, ... Once you do that
moving the object is easy.

oShp.Left = newLeftPosition
oShp.Top = newTopPosition

or

oShp.Left = oShp.Left + 1

The only tricky part is identifying the object so you could assign it to
oShp in the above code.

--David
 
R

Rob

That Sounds Awesome. How do I dentify what the object name/number/tag is
and which of the three should I look for?

Thanks Tons!
 
D

David Marcovitz

Probably, your best bet is to use the object name. You can look on my
site at Example 8.7 to get code that will help you identify (or set) an
object's name:

http://www.PowerfulPowerPoint.com/

Click on "Examples by Chapter" and "Chapter 8."

Then you can use something like:

ActivePresentation.Slides(1).Shapes("Shape Name").Left = 127

or if you're doing a lot to a shape:

Set oShp = ActivePresentation.Slides(1).Shapes("Shape Name")

and then use the code from my earlier post.

The 1 specifies slide 1 so change that if the shape is on a different
slide.

--David
 
R

Rob

My Apologies.... It'll be in edit mode. If it were in presentation mode I
could just use the Custome Actions settings right? Or am I right? Either
way it is to be done in edit mode.
 
J

John Wilson

You could use animation but it wouln't be simple. With vba you can move a
shape when it is clicked on in show mode. It will also be moved when you
return to edit mode.

NOTE though this code will ONLY work in show mode. Give the shape an action
of run macro "mov"

Change the numbers to suit

Sub mov(oshp As Shape)
oshp.IncrementLeft (100)
If oshp.Left + oshp.Width > 710 Then oshp.Left = 10
End Sub
--

john ATSIGN PPTAlchemy.co.uk
Custom vba coding and PPT Makeovers
Free PPT Hints, Tips and Tutorials
http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html
 

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