Solved

Text box values

Posted on 2001-06-06
14
193 Views
Last Modified: 2012-06-21
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!
0
Comment
Question by:TimE
  • 8
  • 5
14 Comments
 
LVL 6

Expert Comment

by:blakeh1
ID: 6160381
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
 
LVL 13

Expert Comment

by:cri
ID: 6161396
blakeh1, its Powerpoint time...
0
 
LVL 13

Expert Comment

by:cri
ID: 6161407
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:TimE
ID: 6162972
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
 

Author Comment

by:TimE
ID: 6162982
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
 

Author Comment

by:TimE
ID: 6162987
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
 
LVL 13

Expert Comment

by:cri
ID: 6163339
What about a half-automated solution ? I mean a macro assisted generation of the hardcoded instructions ?
0
 

Author Comment

by:TimE
ID: 6163631
OK, sounds better. But you've lost me a bit. What exactly R U suggesting?
0
 
LVL 13

Expert Comment

by:cri
ID: 6164606
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
 
LVL 13

Expert Comment

by:cri
ID: 6166891
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
 
LVL 13

Accepted Solution

by:
cri earned 200 total points
ID: 6178869
Ping...
0
 
LVL 13

Expert Comment

by:cri
ID: 6194218
Ping...

Please do not forget this question.
0
 

Author Comment

by:TimE
ID: 6205260
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
 
LVL 13

Expert Comment

by:cri
ID: 6207049
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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
My experience with Windows 10 over a one year period and suggestions for smooth operation
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question