Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get power point slide dimension using vba?

Tags:

powerpoint

vba

I am working on one project. In which i want to find out " Is my textbox going out of slide or not?" . If yes then show error msg.

so my logic is if i found the dimension of the slide then i will use it in IF...Else condition like :

If textbox_position < slide_dimension  then
#Error
end if

If you have any other idea then please tell me.

Thanks

like image 605
Pratik Gujarathi Avatar asked Jan 25 '12 08:01

Pratik Gujarathi


2 Answers

The presentation's .PageSetup.SlideWidth and .SlideHeight properties will give you the dimensions of the slide in points.

Your function would need to do something like (off top of head and out of the air ..):

Function IsOffSlide (oSh as Shape) as Boolean
  Dim sngHeight as single
  Dim sngWidth as Single
  Dim bTemp as Boolean

  bTemp = False ' by default

  With ActivePresentation.PageSetup
    sngHeight = .SlideHeight
    sngWidth = .SlideWidth
  End With

  ' this could be done more elegantly and in fewer lines 
  ' of code, but in the interest of making it clearer
  ' I'm doing it as a series of tests.
  ' If any of them are true, the function will return true
  With oSh
    If .Left < 0 Then
       bTemp = True
    End If
    If .Top < 0 Then
       bTEmp = True
    End If
    If .Left + .Width > sngWidth Then
       bTemp = True
    End If
    If .Top + .Height > sngHeight Then
       bTemp = True
    End If
  End With

  IsOffSlide = bTemp
End Function
like image 178
Steve Rindsberg Avatar answered Sep 24 '22 01:09

Steve Rindsberg


Why you not use a placeholders of PowerPoint to make this? for example:

Sub SetText(IndexOfSlide As Integer, txt As String)
'http://officevb.com
       ActivePresentation.Slides(IndexOfSlide).Shapes.Placeholders(1).TextFrame.TextRange.Text = txt
End Sub

You can call this sub and pass parameters

IndexOfSlide with a number of slide and txt with a text to create.

like image 38
Bruno Leite Avatar answered Sep 23 '22 01:09

Bruno Leite