Consulting

Results 1 to 9 of 9

Thread: Eval functionality needed

  1. #1

    Eval functionality needed

    I have used eval successfully in programming using other languages but it does not seem to be supported in PowerPoint Office 2003 vba.

    I want to run some code which will open the appropriate form based upon which slide is active when you call the function. I am storing the form name as a slide level tag value. All is working great except I can't seem to find a way to basically build a string which contains a run time variable value(the form name) and run the resulting string as a command.
    Below is a sample of my code:


    Sub AAAShowSlideForm()
    Dim strForm As String
    Dim slidename As String
    Dim buildCommandString As String
    On Error GoTo errhandler
    slidename = ActiveWindow.Selection.SlideRange.name
    'Module2.RetrieveSlideTabValue_Slide(slidename, "form") is a routine I have written
    'which returns the value of the specified tag
    strForm = Module2.RetrieveSlideTabValue_Slide(slidename, "form")
    buildCommandString = strForm & ".show"
    eval(buildCommandString)
    Exit Sub
    errhandler:
        MsgBox "There's an error"
    End Sub
    CallbyName does not seem to fit my scenario?
    Any assistance would be much appreciated.

    Thanks
    Last edited by Aussiebear; 04-28-2023 at 08:40 PM. Reason: Adjusted the code tags

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    I don't really like this since it seems brute force, but the PP object model doesn't expose it's objects like I think it should

    Private Sub CommandButton1_Click()
    Dim i As Long
    Dim s As String
    Load UserForm1
    Load UserForm2
    s = ActivePresentation.Slides(SlideShowWindows(1).View.CurrentShowPosition).Tags("FormToCall")
    For i = 0 To UserForms.Count - 1
        If UserForms(i).Caption = s Then
            Load UserForms(i)
            UserForms(i).Show
            Exit Sub
        End If
    Next
    Call MsgBox("If we got here, we must have mis-typed the tag")
    End Sub
    Paul
    Last edited by Aussiebear; 04-28-2023 at 08:41 PM. Reason: Adjusted the code tags

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    It does seem like brute force but I can't see any other way either

    Couple of things though :

    You can get 's' with shorter code
    s = ActivePresentation.SlideShowWindow.View.Slide.Tags("FormToCall")

    And since Userform collection only exists when forms are loaded there's no need to load it again.

    Really can't believe that there isn't a better way but ....
    Last edited by Aussiebear; 04-28-2023 at 08:42 PM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4

    Very good idea

    I have a hard commit for ealy this afternoon but will revisit this routine trying your logic and let you know how it turns out.

    Thank you very much

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    John -- You're right and you're right

    I had experimented with half dozen ways, and did leave the Load ... in from one of my earlier versions.

    PP has a complicated object model (for me anyway) and the Slide Edit / Slide Show modes always get me. I have to Google to get something close to a code fragment that sounds like it will sort of maybe get me a little closer to where I think I might want to go ... maybe

    I thought that Userforms would have a .Name property and a .Tag property that was exposed, but nope

    Paul

  6. #6

    Great Dialog

    The definition of value added collaboration...

    props to both of you!

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Just a thought - are all the forms fairly similar? Maybe you could have code that ADAPTED one form depending on the slide?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8

    Awesome

    Let me start off by observing my username is "dumbpuppy". This choice was evidently profound. I have, in my opinion, written some very cool vba code in excel, access, and now powerpoint. I did not realize you could call userforms from ViewShow mode. This is huge! I already have successfully handled a number of challenges while in ViewShow mode using buttons and images as the UI to trigger events and slide updates.

    For some reason I was under the impression that you had to exit into design view in order to use the userforms. Thank you for inadvertently but providentially setting me straight.

    I officially offer to cut both of your yards durring the summer of 08

    Thanks again...

  9. #9

    Update

    This Code works.

    Thank you for all your assistance and thank you MicroSoft:
    http://support.microsoft.com/kb/207714/


    Sub AAAShowSlideForm()
    Dim strForm As String
    Dim SlideName As String
    On Error GoTo errhandler
    SlideName = ActivePresentation.SlideShowWindow.View.Slide.name
    strForm = RetrieveSlideTabValue_Slide(SlideName, "form")
    VBA.UserForms.Add(strForm).Show
    Exit Sub
    errhandler:
       MsgBox "Error: " & Err.Number & " " & Err.Description
    End Sub
    
    Function RetrieveSlideTabValue_Slide_single(SlideName As String, Tag As String) As Single
    Dim strTagValue As Single
    On Error GoTo ErrorHandler
    strTagValue = ActivePresentation.Slides(SlideName).Tags(Tag)
        RetrieveSlideTabValue_Slide_single = strTagValue
    NormalExit:
         Exit Function
    ErrorHandler:
         MsgBox "Error: " & Err.Number & " " & Err.Description & " - RetrieveSlideTabValue_Slide_single"
         Resume NormalExit
    End Function
    Last edited by Aussiebear; 04-28-2023 at 08:44 PM. Reason: Adjusted the code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •