Solved

Text box values

Posted on 2001-06-06
14
192 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

803 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