View Full Version : [SOLVED:] Eval functionality needed
dumbpuppy
02-12-2008, 08:58 AM
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. :dunno
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
Paul_Hossler
02-12-2008, 06:02 PM
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:rotlaugh:
Private Sub CommandButton1_Click()
Dim i As Long
Dim s As String
Load UserForm1
Load UserForm2
s = ActivePresentation.Slides(SlideShowWindows(1).View.CurrentShowPosition).Tag s("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
John Wilson
02-13-2008, 02:35 AM
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 ....:banghead:
dumbpuppy
02-13-2008, 09:20 AM
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 :thumb
Paul_Hossler
02-13-2008, 10:38 AM
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:bug: ... maybe
I thought that Userforms would have a .Name property and a .Tag property that was exposed, but nope
Paul
dumbpuppy
02-13-2008, 10:57 AM
The definition of value added collaboration...
props to both of you! :bow:
John Wilson
02-13-2008, 11:32 AM
Just a thought - are all the forms fairly similar? Maybe you could have code that ADAPTED one form depending on the slide?
dumbpuppy
02-15-2008, 08:49 AM
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 :cool:
Thanks again...
dumbpuppy
02-15-2008, 11:32 AM
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.