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
Related
Can someone please point me in the right direction to finding the label Powerpoint uses for each shape, active x control, etc... I've researched till I'm blue in the face. Here's what I'm talking about:
I have a very simple slideshow that asks a question in a text box. Just below the question I placed an active x control text box to get the user's answer. All I want to do is take the answer and append it to a text file. Here's the code:
Public Sub WriteAnswerToFile(slideNum As Integer, shapeNum As String)
Dim filePath As String
Dim objFSO As FileSystemObject
Dim objFile As Variant
filePath = "C:\Batch Files\Powerpoint\ButtonPushes\AnswerFile.txt"
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Batch Files\Powerpoint\ButtonPushes\AnswerFile.txt", ForAppending)
objFile.WriteLine (Application.ActivePresentation.Slides(slideNum).Shapes(shapeNum).TextFrame.TextRange)
objFile.Close
End Sub
From each slide, I pass the slide number and the shape designator to the sub routine. The shapeNum is a string because I found that it worked (no better reason than that) for me to pass something like "TextBox 1" as the param. It all works absolutely great if I know the Shape(designator); as in Shape(TextBox1). For the life of me I cannot figure out how to pass the text input by the user into the active x control text box. I have no idea what the designator is. The property sheet for the text input box calls it TextBox1. The Code sheet calls it TextBox1. When I pass that parameter, it prints the question I asked, not the answer, to my text file. I don't know how to call the input text box in my code.
My code prints "How did you hear about us?" to my text file when my code runs with Call WriteAnswerToFile(2, "TextBox 1"). I'm sure that textbox is called textbox 1; it's the first textbox on the slide. I just don't know what Powerpoint labels the user input box.
If there is some sort of Powerpoint scripting or layout page that will define all the shapes in the slidewhow, I'd sure like to be pointed that direction.
You just need to refer to the form part of the Object since this is not a normal shape.
objFile.WriteLine (Application.ActivePresentation.Slides(slideNum).Shapes(shapeNum).OLEFormat.Object.Text)
To clarify from your comment. I think that you have two "Text Box 1". One is "TextBox 1" (note the space) which is the normal textbox and the ActiveX control is "TextBox1" (no space).
If I create a new blank slide and first add a normal text box and then an ActiveX textbox and then run the following code:
For Each shp In Slide2.Shapes
Debug.Print shp.Name
Next shp
The Immediate window will show the following:
TextBox 1
TextBox1
By chance I happened to stumble upon the simplest answer to my question of "finding the label Powerpoint uses for each shape, active x control, etc.."
I am using the Office 16 (Office 365) suite that contains Powerpoint and would not be certain this feature is avaiable to other versions.
On the Home tab in Powerpoint there is an Editing submenu that contains a Select function. As pictured here:
When you click on Select, another submenu appears that shows a Selection Pane function. If you click on that, the selction pane shows up on the right hand of the screen. In that pane you will see all of the objects on the current slide and the names Powerpoint has given to each of them.
It shows there, the discrepancy I was having with calling TextBox(Space)1 and TextBox(NoSpace)1.
This works to be much more expedient for me to grab the name of the shape I want to call in my VBS Scripts.
I am thankful; however, for the time and frustration #Diederik Sieburgh saved me in allowing me to move forward with my project as it is now 2 weeks later that I stumbled upon this information.
I have PowerPoint with a slide master set so all slides have same characteristics. I want to use VBA to place the SlideIndex number of the corresponding slide on each side.
As of now I have it so when you click a button, the slide index pops up in a message box but I want it to pop up in a text box or something on the slide itself.
Here is the script I am currently using..
Private Sub CommandButton_Click()
MsgBox SlideShowWindows(1).View.Slide.SlideIndex
End Sub
I do not want to use a button. I want to automatically have it on each slide when its ran..Thanks in advance
Add a text box to one slide. While it's selected, type this in the Immediate window to name it something meaningful to you:
ActiveWindow.Selection.ShapeRange(1).Name = "SlideNumber"
Then your button handling code can look like:
With SlideShowWindows(1).View.Slide.SlideIndex.Shapes("SlideNumber")
.TextFrame.TextRange.Text = Cstr(SlideShowWindows(1).View.Slide.SlideIndex)
End with
By the way, you don't need VBA for this.
Go to the slide master view. On the master, add a text box wherever you want the slide index to appear.
While you have the text insertion cursor active, choose: Insert | Slide Number
VBA - how can i generate a random number within the specific set 3,5,7,9,11,13.
these numbers represent slide numbers (destinations) which the user will be taken to when a button is clicked.
Edit: Modified to include a more comprehensive solution at request of OP
Objective: Randomly select one of six possible slide numbers to display following the click of a button.
Step 1: Code to randomize slide number selection
Map the target values into an array. Note the number of elements in the resultant array - in this case, 6. Generate a random integer from 1 to 6, and use that value as an index into the array, returning the value at that index position.
Something like the following (untested)
function randomSlideNumber() as Integer
Dim index
Dim targetValues(1 to 6) as Integer
targetValues(1) = 3
targetValues(2) = 5
targetValues(3) = 7
targetValues(4) = 9
targetValues(5) = 11
targetValues(6) = 13
index = Int(6 * Rnd + 1)
randomSlideNumber = targetValues(index)
end function
Step 2: Add slides to a Powerpoint presentation up to the number desired in the random selector
I'm assuming the OP already has at least 13 slides in his presentation :)
Step 3: Add an additional slide to the presentation, and add a CommandButton to it
With the new slide active in Powerpoint, click the 'Developer' tab.
Select a CommandButton from the Controls toolbar, and draw it onto the new slide.
Double-click the CommandButton. This should open the VBA editor with a stub Click event handler for the CommandButton, called CommandButton1_Click().
Modify the handler code as follows:
P
Private Sub CommandButton1_Click()
SlideShowWindows(1).View.GotoSlide randomSlideNumber
End Sub
Step 5: Start the slide show, using the slide with the new CommandButton as the starting point
With the new slide active, select the "Slide Show" tab from the ribbon bar
Click "From Current Slide" from the "Start Slide Show" bar.
Step 6: Click the CommandButton on the slide, and verify that the active slide changes to one of those returned by the randomSlideNumber() function
Voila! :)
Code Discussion
Note: This involves a little detail about the PowerPoint VBA object model.
Clicking the CommandButton in the slide created in Step 3 fires the CommandButtton1_Click() event handler created in Step 4. The event handler then goes to the current View of the first SlideShowWindow object SlideShowWindow(1).View, and calls the GotoSlide method of the View. The GotoSlide method expects a slide number as a parameter, which is provided by the call to the 'randomSlideNumber' function defined earlier. That function should return one of 3, 5, 7, 9, 11, or 13.
That should do the trick.
Caveats: There is obviously no error handling in this code; its addition is left as an exercise. Further, this has not been extensively tested against the very latest version of Powerpoint, but did work in the test shell I created.
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!
I am trying to write a macro in VBA (Excel) that is assigned to a Checkbox. Whenever the checkbox is clicked, an "autoshape" will change its "order" from "Send to Back" to "Send to Front".
Basically, I am trying to create a dashboard with multiple panels, so that users can access information without moving between sheets. Each panel will have a rectangular autoshape as its background and the components of the panel will be "grouped" within the autoshape.
Can this be done? I would greatly appreciate any ideas into writing the code.
Thanks,
I'm not quite following your larger goal, but in order to bring a shape to the front use this:
If MyCheckBox.Value = True Then
MySheetName.Shapes("MyShapeName").ZOrder msoBringToFront
End If
You should select your desired ZOrder movement from the MsoZOrderCmd enumeration and your code should be in the Change event routine for your checkbox control.
EDIT:
You could also refer to the shape by its index number. For example:
MySheetName.Shapes(0).ZOrder msoBringToFront
Also, to get the name of a shape, either click it and look in the Name Box in the upper left corner of Excel (below the toolbars), or iterate through all the shapes like so:
Sub Macro1()
Dim MyShape As Shape
For Each MyShape In Sheet1.Shapes
Debug.Print MyShape.Name
Next MyShape
End Sub