2012-01-25 13 views
8

Pracuję nad jednym projektem. W którym chcę się dowiedzieć "Czy mój tekst jest pusty?" . Jeśli tak, wyświetl komunikat o błędzie.Jak uzyskać rozmiar slajdu Power Point za pomocą vba?

więc moja logika jest, jeśli uważam, że wymiar suwaka następnie użyję go w stan IF ... Else jak:

If textbox_position < slide_dimension then 
#Error 
end if 

Jeśli masz inny pomysł to proszę mi powiedzieć.

Dzięki

Odpowiedz

16

Właściwości prezentacji .PageSetup.SlideWidth i .SlideHeight podają wymiary slajdu w punktach.

Twoja funkcja musiałaby zrobić coś takiego (off czubku głowy i z powietrza ..):

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 
+0

Dobry kod Steve! –

+0

Hej dzięki kumplu. jesteś zbyt dobry –

+0

Dzięki, ludzie. –

1

Dlaczego nie używasz symboli zastępczych programu PowerPoint, aby to zrobić? na przykład:

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

można nazwać sub i przekazać parametry

IndexOfSlide z wieloma zjeżdżalnią i TXT z tekstem do tworzenia.

+0

dzięki dużo Bruno. Pozwól mi spróbować. –

Powiązane problemy