1

I want to make a PowerPoint macro. This is a macro that selects with textbox slide number, left, top.

'for example

Sub test1()

ActivePresentation.Slides(1).Select

with Left:=-300, Top:=100

End With

Dim TBox1 TBox1 = ActiveWindow.Selection.TextRange.Text

MsgBox (TBox13) '----error

End Sub

'select text box

  • It's not clear what you want to do. Are you trying to get the text from a text box that's at at 300 left and 100 top position? – Steve Rindsberg Jun 13 '22 at 13:55
  • The first is to select the text box with Left 300 and top100 on slide 1 The second is to declare the text inside the textbox so that it can be used by other macros. – 컴알모옷 Jun 13 '22 at 15:06

1 Answers1

0

Here's some sample code that'll do what you want. Rather than make it specific to your question, I wrote something more general-purpose that you can use to find any shape at any position on any slide you like.

Option Explicit

Sub AddTestTextbox()
' Use this to quickly add a text box to test with
' at the right coordinates
    Dim oSh As Shape
    With ActivePresentation.Slides(1)
        Set oSh = .Shapes.AddTextbox(msoTextOrientationHorizontal, 300, 100, 200, 100)
        oSh.TextFrame.TextRange.Text = "Some random text to test with"
    End With
End Sub

Sub Test()
    Dim oSh As Shape
    Set oSh = FindShapeAt(ActivePresentation.Slides(1), 300, 100)
    If Not oSh Is Nothing Then
        If oSh.HasTextFrame Then
            If oSh.TextFrame.HasText Then
                MsgBox oSh.TextFrame.TextRange.Text
            End If
        End If
    End If

End Sub

Function FindShapeAt(oSl As Slide, sngLeft As Single, sngTop As Single) As Shape
    Dim oSh As Shape
    For Each oSh In oSl.Shapes
        If oSh.Left = sngLeft Then
            If oSh.Top = sngTop Then
                Set FindShapeAt = oSh
                Exit Function
            End If
        End If
    Next
End Function
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34