Solved

Text box values

Posted on 2001-06-06
14
190 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now