Text box values

Hi Folks,

I've written code to call out from Powerpoint to WinSock32.dll to run a ping command. I've stuck the code, as a macro, behind a text box and supplied the IP address and it's worked fine.

I.E. MyPingCommand(strIPaddress,ECHO)

Forget the second agrument it doesn't matter.

ALL I want to do is to reference the value in the textbox I'm clicking and pass that value in as the IP Address. How do I do it?

I'm feeling very generous, so there's 200 points on offer!
TimEAsked:
Who is Participating?
 
criConnect With a Mentor Commented:
Ping...
0
 
blakeh1Commented:
You can use the following, just changes names and indexes as needed (Note this will work only if you added it from the Control Toolbox toobar, not the Forms toolbar)    


Dim txt As Object
    Dim sText As String
    Set txt = Worksheets(1).Shapes("TextBox1").OLEFormat.Object
    sText = txt.Object.Value
0
 
criCommented:
blakeh1, its Powerpoint time...
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
criCommented:
TimE, I played around a bit, but did not find yet a solution worth to be posted.

Additionally, I have questions:

a) Is a solution which is 'hardcoded' for each textbox acceptable ? >> Use ActionSettings

b) Does it have to be a general solution ? >> No clue, Powerpoint/VBA is much weaker than Excel/VBA or even Word/VBA, not to speak about my own practice of it.

0
 
TimEAuthor Commented:
Yeah, basically it does have to be PowerPoint, unless it really can't be done.

To give you some more info. The PowerPoint Slides are network diagrams and the text boxs are the IP addresses associated with the network components. My plan is (was?) to allow you to click the IP address in the Slide and do a ping test, thus saving getting up a DOS prompt and typing "ping www.xxx.yyy.zzz"
0
 
TimEAuthor Commented:
Oh, yeah, I guess I could Hardcode it, I mean I've already proved that works no problems. But a nice generic Sub with the agrument passed in would be so much sweeter.
0
 
TimEAuthor Commented:
Oh, yeah, I guess I could Hardcode it, I mean I've already proved that works no problems. But a nice generic Sub with the agrument passed in would be so much sweeter.
0
 
criCommented:
What about a half-automated solution ? I mean a macro assisted generation of the hardcoded instructions ?
0
 
TimEAuthor Commented:
OK, sounds better. But you've lost me a bit. What exactly R U suggesting?
0
 
criCommented:
Something like this:

Option Explicit 'to prevent typos

Sub CodeGenerator()
  'Writes a code snippet for each textbox on slide one
 
  Dim sPath As String, myShape As Shape
 
  sPath = "c:\temp\PPT_VBA.bas" '<< Adapt as required
  Open sPath For Output As #1
  With ActivePresentation.Slides(1) '<< Adapt or make additional loop
    For Each myShape In .Shapes
      With myShape
        If .TextFrame.HasText = True Then
          'ATTENTION: Starting point only, adapt where necessary
          Print #1, "With Shapes(""" & .Name & """).ActionSettings(ppMouseClick) "
          Print #1, "  .Action = ppActionRunMacro"
          Print #1, "  .Run = " & .TextFrame.TextRange.Text
          Print #1, "  .AnimateAction = True"
          Print #1, "End With"
          Print #1,
        End If
      End With
    Next myShape
  End With
  Close #1
  MsgBox sPath & "  finished !"
End Sub
0
 
criCommented:
Forget previous post, this solution here starts to get sensible:


Option Explicit 'to prevent typos

Sub PrimeTextboxFrameActionSettings()
 'Attention: Clicking _text_ of textframe has no effect (yet) as it
  '          has its own action setting !
 
 Dim myShape As Shape
 
 With ActivePresentation.Slides(1) '<< Adapt or make additional loop
   For Each myShape In .Shapes
     With myShape
       If .TextFrame.HasText = True Then
         With .ActionSettings(ppMouseClick)
          .Action = ppActionRunMacro
          .Run = "PlaceHolder" 'Shape is passed as argument by PPT
         End With
       End If
     End With
   Next myShape
 End With
 MsgBox "All textbox FRAMES are primed !"
End Sub

Sub PlaceHolder(myClickedShape As Shape)
  MsgBox myClickedShape.Name & " contains " & myClickedShape.TextFrame.TextRange.Text
End Sub
0
 
criCommented:
Ping...

Please do not forget this question.
0
 
TimEAuthor Commented:
Sorry I haven't got back sooner, I was taking a few days vacation.

Mighty fine answer! I've added some constraints so only textboxes containing IP address actually get primed and stuck that loop to go through all slides.

Thanks again, enjoy your points!!
0
 
criCommented:
ThAnk you. Hope you did enjoy your vacation. Did not want to pester you, but as approx. 40% of the questions are abandoned I wanted to be sure this solution does not get lost, it took quite a while to figure out that Powerpoint passes the textbox name as argument...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.