2012-01-25 34 views
8

私は1つのプロジェクトに取り組んでいます。私は「私のテキストボックスがスライドから外れているかどうか」を知りたいですか? 。はいの場合、エラーmsgを表示します。vbaを使ってパワーポイントスライドの寸法を取得する方法は?

ので、私のロジックは、私はスライドの大きさを発見したならば、私はIFにそれを使用しますが... else条件のように:

If textbox_position < slide_dimension then 
#Error 
end if 

あなたが他のアイデアを持っている場合は、私に教えてください。

ありがとうございます。

答えて

16

プレゼンテーションの.PageSetup.SlideWidthプロパティと.SlideHeightプロパティは、スライドのサイズをポイント単位で示します。

あなたの機能のようなものを行う必要があるだろう(頭の上から、空気のうちに...):

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

良いコードスティーブ! –

+0

おはよう、ありがとう。あなたはあまりにも良いです –

+0

ありがとう、人々。 –

1

なぜPowerPointプレースホルダを使用しないのですか?例えば:

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

あなたはこのサブを呼び出すことができますし、作成するためのテキストとスライドとTXTの数とパラメータ

IndexOfSlideを渡します。

+0

どうもありがとうございましたブルーノ。私が試してみましょう。 –

関連する問題