Powerpoint : determine current slide/screen position with VBA ?

J

jm.almeras

Dear vba experts
The Powerpoint object model provides a way for finding the current zoom
factor : ActiveWindow.View.Zoom, but there is nothing that returns what
portion of the slide is currently being displayed (with a big zoom factor,
one might be working in the top left corner, the bottom right ...)
Ideally i need to find the slide coordinates of the 4 corners of the current
window (which depends on different display options, whether the rulers are
being displayed, presence of the slides navigator, etc.) If anyone can help
i would be very grateful
Thank you
Jean-Marie
 
C

Chirag

It also depends on whether you have any off-slide objects. You can get to
the slide's window by enumerating the child windows of the PowerPoint
window. Look for a window with class name "paneClassDC" located on top-right
corner. The slide thumbnails pane and the notes pane are also of the same
class but they are never located at top-right. From here on, to find the
slide's bounding rectangle, you need to take care of quite a few things.
Rulers is not among them as they lie outside of the slide window.

What is it that you are after? There may be simpler ways to achieve that.

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
J

jm.almeras

Hi Chirag, thank you for the tips, however i must say i am not a windows API
expert. If you could tell me the api function names to call, starting from
that i might be able to find my way to the solution.

The reasons behind my question is the following : I work day long with
Powerpoint, and i have progressively built a lot of vba programs to assist
me in my work. Example : i have various buttons to add different objects on
the slide on which i am working (textbox, legend, images...). Now if i am
working with a zoom factor on a portion of the slide, i wish to add the new
object on the center of the portion of the slide being displayed. I have a
button that will enlarge the screen around the objects currently selected
and another button that will do the reverse (step forward / step backward)
and for that i also need to know precisely the current slide portion.

Thank you for your help

Jean-Marie
 
M

M. Brown

Along similar lines, I am trying to write a VBA macro that will drop a text
box at the mouse cursor location via keyboard shortcut. I have been
partially successful. The problem is that I cannot seem to find a method for
determining the location of the slide relative to the screen. All I need is
one corner or the center of the slide.

I use GetCursorPos Lib "user32" to get the mouse cursor position in pixels.
Then I use the PixelsToPoints function in Word 11.0 Object Library so that I
can convert the mouse cursor position to points. I have to scale the
resulting value to account for the zoom size of the slide and apply an offset
to account for the edge of the slide relative to the screen origin. Here is
my code. It works as long as I am using a monitor with 1280 by 800
resolution and have the slide centers and zoomed at 65%.

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Public Function GetXCursorPos() As Long
Dim pt As POINTAPI
GetCursorPos pt
GetXCursorPos = pt.X
End Function

Public Function GetYCursorPos() As Long
Dim pt As POINTAPI
GetCursorPos pt
GetYCursorPos = pt.Y
End Function

Public Sub DropXMacro()
Dim MouseCursorPosX As Long
Dim MouseCursorPosY As Long

If ((PixelsToPoints(GetXCursorPos(), False) / (ActiveWindow.View.Zoom /
100)) - 355) < 0 Then
MouseCursorPosX = 0
ElseIf ((PixelsToPoints(GetXCursorPos(), False) /
(ActiveWindow.View.Zoom / 100)) - 355) > 720 Then
MouseCursorPosX = 720
Else
MouseCursorPosX = (PixelsToPoints(GetXCursorPos(), False) /
(ActiveWindow.View.Zoom / 100)) - 355
End If

If ((PixelsToPoints(GetYCursorPos(), True) / (ActiveWindow.View.Zoom /
100)) - 226) < 0 Then
MouseCursorPosY = 0
ElseIf ((PixelsToPoints(GetYCursorPos(), True) / (ActiveWindow.View.Zoom
/ 100)) - 226) > 540 Then
MouseCursorPosY = 540
Else
MouseCursorPosY = (PixelsToPoints(GetYCursorPos(), True) /
(ActiveWindow.View.Zoom / 100)) - 226
End If


ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizontal, MouseCursorPosX, MouseCursorPosY, 40, 23).Select
ActiveWindow.Selection.TextRange.Text = "X"
End Sub
 

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