I am trying to make a review game in PowerPoint 2007. I would like to be able to have two text fields where, in the show, the person controlling the game would then enter a team name in the two text fields. It would then save the data and then, on the next slide, show the team names on opposite sides of the presentation. I would imagine it would take the input from the text field, save it to a variable, and have a label with the text of that label equal to the input of the text field.
Before Reading this
"SlideX" = the Slide that Stores your Values
SlideO = AnySlideNumber
Ok First you want to make 1 slide that is hidden. to change the slide without opening this one you need to use hyperlinks for example, change slides with a Image button with hyperlinks or you could make a Developer Button that changes slide with ActivePresentation.SlideShowWindow.View.GotoSlide (SlideO)
in the one slide that is not hidden that inputs the team names make two labels, that will be editited and name them Like "Team1" and "Team2" or something like that. ok here Double click any of them and you'll get the code for it, just ignore that and paste this
Private Sub Save()
' Change X to The Slide that stores the numbers!
SlideX.SaveValuesIntoText Team1.Caption Team2.Caption
End Sub
after you have done that go a head and Create the Slide that stores the values Eg. the slide where you input your names (p.s. i like your idea) make two Textbox's named "Team1Name" and "Team2Name" with 2 button's (1 = Save, 2 = Nextslide) once you done that also open up thats code and paste this in
Public Function SaveValuesIntoText(Team1 As String, Team2 As String)
Team1Name.Caption = Team1
Team2Name.Caption = Team2
End Function
If done correctly you should of had the values saved into the powerpoint slide, and now you can just simple retrieve them with
Private Sub RetrieveValues()
Team1 = X.Team1Name.Caption
Team2 = X.Team1Name.Caption
Label1.Caption = Team1
Label2.Caption = Team1
End Sub
that should do it. P.s. if you want to retreive the Values Automaticly in the Slide that displays the teams you need to add this Code into it
Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
If Wn.View.CurrentShowPosition = 1 Then
RetrieveValues
End If
End Sub
IF THIS DOESNT WORK, i made a syntax error tell me what it is and ill correct it!
Related
I am trying to copy the slide name (not the title) for a slide to appear within a text box on the same slide. I can get the entire list of slide names to output to an external file or appear in the Immediate Window. Is there some sort of copy/paste syntax or isolated output that will work?
The expectation for stackoverflow questions is that you show your working code, so people can see what you've tried, adding context to the question that you're asking. However maybe try something like this, which simply adds a textbox containing the slide name to each slide:
Option Explicit
Public Sub SlideNames()
Dim WorkSlide As Slide
Dim WorkTextBox As Shape
For Each WorkSlide In Application.ActivePresentation.Slides
Set WorkTextBox = WorkSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 100, 20)
WorkTextBox.TextFrame.TextRange.Text = WorkSlide.Name
Next
End Sub
I have a userform containing 3 frames that all include several textboxes. I would like to be able to tab the textboxes across frames.
So, something like this: Frame1 - Textbox1 > Frame2 - Textbox1 > Frame3 - Textbox1 > Frame1 - Textbox2 > Frame1 - Textbox3 > Frame2- Textbox2
The textboxes are dynamically added and stored in an array according to the desired taborder, so the desired order is easily accesible. I just cant seem to find a way to apply this.
It would of course be possible to change the frame layout. However, the frames are used both to control the placement of the textboxes, and also to add separate scrollbars if the amount of textboxes exceeds the frame area.
Is something like this possible? Any help or suggestions much appreciated.
Edit: Added picture of the 3 frames
Frames
Edit2:
I think destination-datas comment put me on the right track.
I created a class module
Public WithEvents TxtBox1 As MSForms.TextBox
Private Sub TxtBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox ("Test")
End Sub
Private Sub TxtBox1_change()
MsgBox ("Test")
End Sub
And then in the sub that generates the textboxes, for the textboxes where I want to jump frames I do:
Dim tabArray1() As New TabBox1
Dim inputfelt As MSForms.TextBox
Set inputfelt = Hovedvindu.SkjemaFrame.SenderFrame.Controls.Add("Forms.TextBox.1", "M" & i & "SenderNavn", True)
Set tabArray1(i).TxtBox1 = inputfelt
This adds all the correct textboxes to an array so that I can make an Exit event that changes focus, which I think should not be too diffucult.
However, I cant seem to get the events to fire properly.
The change event seems to work when I change the textboxes with a sub, for example when I tested that the correct textboxes are added to the array by looping through and changing the text of the textboxes in the array. But when I change the textboxes manually, nothing happens. The exit event doesnt seem to work at all.
Im not too experienced with event handling, so I might have missed something.
I found an acceptable solution. The approach described in Edit 2 of the original post worked once I moved the definition of the TabArray() outside the sub, so that I keep track of the textboxes after the sub is ended.
I have one array, and one class module for the "end" textboxes on each of the 3 frames. The class modules tracks keydown on Tab. The 3 class modules are identical, except that they store the tabindex of the textbox from where the focus jumps to another frame in 3 different hidden labels on the userform. Keeping track of the tabindex allows me to know where to start when focus comes back to a frame.
the 3 class modules look like this:
Public WithEvents TxtBox1 As MSForms.TextBox
Private Sub TxtBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = vbKeyTab Then
'store tabindex
Hovedvindu.Controls("SisteTab1").Caption =
Hovedvindu.SkjemaFrame.SenderFrame.ActiveControl.TabIndex
'call sub that moves the focus
flyttfokus (1)
End If
End Sub
The sub that moves focus is shown below. Input is just an integer (1,2 or 3) depending on which class module the call comes from, and thus which frame to move from/to. The sub reads the 3 hidden labels to know which textbox to start from when the focus is moved to a new frame. Error handling in the last case is for when the focus is moved from the very last textbox in the 3d frame. This will try to move focus to a non-existing textbox in the first frame, which will throw an error which can be ignored.
Sub flyttfokus(SisteFrame As Integer)
Dim St1 As Integer
Dim St2 As Integer
Dim St3 As Integer
St1 = CInt(Hovedvindu.Controls("SisteTab1").Caption)
St2 = CInt(Hovedvindu.Controls("SisteTab2").Caption)
St3 = CInt(Hovedvindu.Controls("SisteTab3").Caption)
Select Case SisteFrame
Case 1
Hovedvindu.SkjemaFrame.MottakerFrame.Controls(St2 + 1).SetFocus
Case 2
Hovedvindu.SkjemaFrame.InfoFrame.Controls(St3 + 1).SetFocus
Case 3
On Error Resume Next
Hovedvindu.SkjemaFrame.SenderFrame.Controls(St1 + 1).SetFocus
On Error GoTo 0
End Select
End Sub
This solution will work as desired when starting from the very first textbox. If the user however, mouseclicks to a textbox for example on the second line and then starts tabing, focus will be moved back to the first line when focus is moved between frames. This is because the variables (labels) that keeps track og the Tabindex from where to start when a frame receives focus are only updated as the user tabs through the sheet. It is probably possible to update these variables on mousclick to a textbox, based on the amount of textboxes that are generated by the program. For my purposes this is not deemed necessary.
I am looking to view an image from the worksheet in an Image control on a userform.
This image will change based on the value on a combobox. I have inserted (Using: Insert -> Pictures) a couple of images into "Sheet1" of my workbook and named them "Picture1" & "Picture2".
I have created the below UserForm:
Form http://im56.gulfup.com/msKyqi.png
And this is the code that I am trying to use in order to load the images from the sheet, but unfortunately, this is not working at the moment.
Private Sub ComboBox1_Change()
UserForm1.Image1.Picture = LoadPicture(Worksheets("Sheet1").Shapes(ComboBox1.Value))
End Sub
Private Sub UserForm_Initialize()
UserForm1.ComboBox1.Clear
UserForm1.ComboBox1.AddItem "Picture1"
UserForm1.ComboBox1.AddItem "Picture2"
UserForm1.ComboBox1.Value = "Picture1"
UserForm1.Image1.Picture = LoadPicture(Worksheets("Sheet1").Shapes(ComboBox1.Value))
End Sub
Every time I run this code I get the below error:
Error http://im43.gulfup.com/YoWvTp.png
Please advise.
I figured it out!
As I am using a UserForm there is a workaround to the issue.
Instead of having the images in the worksheet to then try and load them in the form I tried having them in the UserForm in the first place, here is how.
Create a frame on your userform:
Frame http://im88.gulfup.com/Moy8I6.png
Set the visible property of the frame to "False":
Visible http://im88.gulfup.com/sAIQqh.png
Insert your images by adding a picture control and loading the images, you can add as many images as you need:
Images http://im88.gulfup.com/oas0EQ.png
Name the images:
Name http://im88.gulfup.com/cIO317.png
Drag all the images one over the other into the frame, (you can then move the frame into a corner so it doesn't bother you:
Drag http://im88.gulfup.com/1fOSut.png
Move Away http://im88.gulfup.com/Q1fzKd.png
Next create a picture control, this is what you will use to display the picture based on a selection:
Form View http://im88.gulfup.com/X1UVRB.png
In this example, I am going to use a combobox for the selection. Now insert the below code in to the form which is pretty straight forward:
Private Sub ComboBox1_Change()
' Image1 is the name of the created picture control
UserForm3.Controls.Item("Image1").Picture = UserForm3.Controls.Item(UserForm3.ComboBox1.Value).Picture
End Sub
Private Sub UserForm_Initialize()
UserForm3.ComboBox1.AddItem "Argentina"
UserForm3.ComboBox1.AddItem "Brazil"
UserForm3.ComboBox1.AddItem "Chile"
End Sub
As you will see, the frame with the pictures is Hidden, and the image is changing inside the picture control based on a selection:
Result http://im88.gulfup.com/MSqyHF.png
I think it's the better way to go as opposed to exporting the images from the worksheet to a Temp folder and then loading them back into the picture controls.
The LoadImage() function expects a filename (which can be fully qualified with a drive letter and path). You are getting a type mismatch because it wants a string, and you are giving it an image object.
There is, as far as I know, no simple way to put an image that resides in the current application into an image control. The (hackish) workaround that I know about is to export the image to a file, and then import that same file using LoadImage().
This is the same path you have to go down if you want to embed a chart that updates dynamically into a userform. You export the chart as an image (e.g., a JPEG), and then use LoadImage() to pull the image back into the image control.
I know this post is ancient, but I found my way here. I came up with a slightly different solution to this problem. I have about 30 pictures I need to load based on a combo-box selection. First, all combo-box options (for discussion "XX") are saved to a separate worksheet which is "Very hidden" from the user and loaded into the combobox on userform activation. On the userform a frame was added, and within the frame 30 image-boxes all overlapping perfectly were placed. Each image-box was carefully named "Img_XX" where XX is the simple two-letter identifier.
With this setup it is now possible to iterate through each "Control" (the image boxes) in the Frame and hide them all, except the one with a name that matches the combo-box value. The code in the userform module, within the Combobox_Change() function, looks something like this:
Private Sub ComboBox_Change()
Dim SearchValue as String
SearchValue = me.Combobox.value
Dim Ctrl as Control
For each Ctrl in Me.TestFrame.Controls
If Ctrl.Name Like "img_" & SearchValue Then
Ctrl.visible = True
else
Ctrl.Visible = False
End If
next Ctrl
End Sub
I hope this helps, let me know what you think. :)
Longtime viewer, first time question asker.
I'm currently working with UserForms within MS Word and have a particular form that can have up to 20 different labels and accompanying textboxes with varying texts. I have all but the first hidden while not in use, however I would like the next label and text box to become visible following input in the previous textbox. So if you enter data (anything) in the first textbox, the next label and text box will become visible. Does this make sense? I've seen other responses here suggest using AfterUpdate() rather than Change() or Click() but can't figure out how to use any of them. I would share my code but at this point I don't have any code to share, other than my labels and textboxes are lblField1 txtField1, lblField2 txtField2...
Any suggestions?
I would suggest using Change event, when using AfterUpdate you need to leave you TextBox for a while to fire the event. If you have only one TextBox visible there is nothing to move to. If you have more TextBoxes you would need to move back to fire AfterEvent and I don't think this is what you expect.
So, double click wherever on your userform and add the following code in code area:
Private Sub txtField1_Change()
txtField2.Visible = True
lblField2.Visible = True
End Sub
Next, add next portion for next textbox:
Private Sub txtField2_Change()
txtField3.Visible = True
lblField3.Visible = True
End Sub
And so on, if only you have an order in controls name you just need to change numbers in the end of control names.
Is it possible to identify the shape ID that triggers a mouseover on a powerpoint presentation.
What I want to do is have a series of shapes on a slide with titles, and when the user mouseovers a shape, I want to use VBA to show more details about the shape in another part of the page, possibly in a separate help text box. I could then use the selected shapes ALt Text to display in the help box. What i can't see is how to identify what shape has triggered the mouseover macro. Is this possible? If I can identify the shape that triggered the action, I could then get info about that shape.
The Shape object in PowerPoint does not allow you to interact with its events as you normally would with other objects in VBA code. The only two 'events' that are exposed are not actually VBA events. They are a special class called Actions, and they are 'ppMouseOver' and 'ppMouseClick'. If you know all the information about your shapes and their corresponding information beforehand, you could write some code to do what you want, but it would all be hard-coded, which is probably not what you want.
You could run a routine something like this when the presentation starts:
Sub SetActionsRoutine()
Shape1.ActionSettings(ppMouseOver).Action = ppActionRunMacro
Shape1.ActionSettings(ppMouseOver).Run = "showInformation1"
Shape2.ActionSettings(ppMouseOver).Action = ppActionRunMacro
Shape2.ActionSettings(ppMouseOver).Run = "showInformation2"
...
...
End Sub
And then whenever you did a MouseOver of those shapes, one of the following routines would run.
Sub showInformation1()
myTextBox.Text = Shape1.AlternativeText
End Sub
Sub showInformation2()
myTextBox.Text = Shape2.AlternativeText
End Sub
This is very limited and requires that you write a subroutine for every shape on your slide. Probably not the approach you want, but again, with PowerPoint, your options are very limited.
New to StackOverflow, late to answer, but you can do this:
Sub RespondToShape(oSh as Shape)
MsgBox "You clicked " & oSh.Name
End Sub
Assign every shape you want to interact with an Action setting of Run Macro and choose RepondToShape as the macro.