Hide/unhide slides not work fine if I go to the end of the show - vba

I have a powerpoint with a macro.
1) at the begin, the last 4 slides of the show are hidden.
2) When I run my show, I go on a slide which contains 4 checkboxes. These checkboxes can hide or unhide the last 4 slides. If I check, then, the slide is unhidden and if I uncheck, in the same way, the slide is hidden. For example, I check the checkbox number 3 and only the slide number 3 is unhidden. Or, I check the checkboxes number 2 and 4 and only the slides number 2 and 4 are unhidden. On the contrary, if I uncheck the checkbox, for example number 2, I hide the slide number 2.
3) for the example, I check the checkboxes number 1 and 3 which unhide the slides number 1 and 3.
4) When I go to the next slide after this, only the slides number 1 and 3 are unhidden. Good.
5) Then, I go back to the slide containing the checkboxes.
6) I uncheck the checkboxes number 1 and 3 and check the number 4.
7) I go to the next slide and only the slide number 4 is unhidden. Good.
8) Now, I go to the next slide from where I'm at, the slide number 4, and there is no more slide. So, I see the end's screen of the show.
9) If I decide to go back to the show from this end, I see the slide number 4, but also, the slides number 1 and 3 that I unchecked before at the 6). My trouble is that I don't understand why the slides that I unchecked which would be hidden, are unhidden if I go back from the end's screen of the show ?
I try to find an explanation on the Web but I didn't find something on this trouble.
Thanks for your help.

I can repro something like this this w/o using code in PPT 2016.
If this will run on a PC that you control, do this:
File | Options | Advanced
Under "Slide Show", remove the check next to "End with black slide"
Click OK
Now PPT will simply end the show when the user is on the last slide and tries to go forward.

Related

How to start the Fancybox Carousel on the very first slide when infinite is equals to 1?

Is it possible to start the carousel on the very first slide but keeping the slidesPerPage: 1 and infinite: true? when you land on the page like this image?
Right now it starts with cards 6, 1, 2. Please see this demo right here.
Demo Playground
I don't even know why it would start to number 6 when the slide starts at number 1. If I remove the slidesPerPage: 1, the carousel would slide at 3 slides per turn and I feel that's a bit too fast. Is there a way to make it slide by 1 and still start it with the first slide?
Or is it possible to land on the page where the carousel starts on slide 2? That will make number 6 card to the far left, hidden and makes card 1, 2, 3 the only visible card when you land on the page.

VBA PowerPoint - fill in textbox based on another textbox content on different slide

I am a beginner with VBA, and I was wondering whether VBA could help me to automate presentation creation process.
My presentation template has on the top of each slide a textbox, which I would like to fill in with the text from a different slide.
Example:
Slide 1 (Divider slide): includes only 1 textbox with text e.g. 1) Project scope
Slide 2, 3, 4 ... (Content slides): include title, charts, other text box, etc. - but also 1 "descriptive" textbox placed always in the same place on the top of each slide
I would like this "descriptive" textbox to include text from Slide 1 (Divider slide).
Text in the "descriptive" textbox would change every time a new Divider slide would be detected, i.e. different "descriptive" textbox for each presentation part.
Not sure whether this can be done with VBA as I could not find anything similar online.
Thank you a lot for any information!

Excel Form buttons remain in same place, but TopLeftCell is different (all after parent row is unhidden)

Cutting right to the chase, I have a tab with 4 Excel Tables stacked on top of each other. Each row has its own "up" and "down" buttons in the column to the left of the table, like this:
I shrunk the buttons to fit within the same cell (rowheight of 20). This allowed me to use the cell's TopLeftCell.Row property as follows: When clicked, stuff from the button's row is copy-pasted to the row above/below. This is the basic code:
currRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
If InStr(Application.Caller, "Up") > 0 Then
Move_Project_Up currRow
Else
Move_Project_Down currRow
End If
When the user gets to this tab, any empty table-rows are hidden (with a Rows(rr).EntireRow.Hidden = True). The buttons Move and size with cells so they are automatically hidden). All visible buttons work as expected. However, sometimes a user wishes to move a project from the top of one table "up" to the bottom of the above table (i.e. to a currently hidden row). You can imagine wanting to move data from row 312 "up" to row 244 in the image below:
The code successfully makes the move and unhides the row. HERE'S THE PROBLEM: when the row is unhidden, the buttons are dark gray and their TopLeftCell.Row is wrong:
They are NOT disabled. When clicked, they still trigger the assigned macro. However, I can see from a Debug.Print that their TopLeftCell.Row is not necessarily the row they are actually in. In the image above, BOTH SETS OF BUTTONS have a TopLeftCell.Row of 97. That's correct for the first set, but not the second.
Any thoughts on why this might be happening? I suspect it has to do with the unhiding of the rows, and/or the fact that there's a lot happening on this tab (e.g. over 10,000 array formulas).
Thanks in advance!
As one commenter (jkpieterse) suggested, setting the .Top property of the "broken" buttons to the .Top value of a cell in the same row worked!

powerpoint, vba, generate a random number from a specific set

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.

Branching Slides in PowerPoint (VBA)

I am trying to create a back button but using hyperlinks it simply just takes me to the previous page and ends up in a loop... e.g. if I have slide 1 which has links to slide 3, 4 & 5 then slide 3 links to 6 & 7. If I'm currently on slide 7 and click back it successfully takes me back to slide 3 but then I want to click back and end up at slide 1 rather than back to slide 7 (hopefully I'm making some sense!).
I presume the only way for me to do this is with VBA can anyone give me some advice on best way to create a back button? (I'm using PowerPoint 2007)
I was struggling with a similar problem today and made a little "breadcrumb"- generator for powerpoint. There is no link feature yet, but you can implement it if you like:
Github Project
Essential parts of the code
Public Sub breadcrumbs(ByVal count As Integer, ByRef titles() As String)
Dim cntr As Integer
Dim content() As String
Dim margin As Integer
Dim width As Integer
'----------------------------
' Set Titles
content = titles
cntr = 0
' Set width
width = ((Application.ActivePresentation.PageSetup.SlideWidth - (margin * count * 2) - 20) / count) - 50
' Loop through all slides
For Each sld In Application.ActivePresentation.Slides
' generate breadcrumb for each title
For Each con In content
sld.Shapes.AddShape(1, (50 + (width * cntr)), 15, width, 50).TextFrame.TextRange.Text = con
cntr = cntr + 1
Next con
cntr = 0
Next sld
End Sub
It sounds like you want a 'breadcrumb trail' of visited slides, instead of a simple back button. Thus you need a way to preserve the trail.
This could be addressed with a dynamic array. New browsing would add records to the array. Your "Next" and "Previous" locations would be found by moving up or down the array. You'll have some mild logic puzzles. I hate to refer you a generic resource, but I'm out of specifics and an overview may be helpful.
UPDATE: I've wanted this in the past for MS Access, and thought I'd readily find a snippet solution. But now I go to search (thinking it will convert over for you easily as well), and I don't find anything. This is surprising because I imagine it would be fun to built. Or ... it's harder to build than I anticipate.
There is a really cumbersome way to do this in PPT directly with no programming. You'll need "forward-facing slides" and 2 sets of "backward-facing slides". Backwards ones are two types - direct-back and home-back. They can all be identical, but make the backward ones hidden (e.g. instead of "Slide 3" you'll need "Slide 3a" and "Slide 3b" and "Slide 3c".). They are hidden so that when you progress through normally, you won't see them, but when you link to them, they will appear. Your link list on the "a" slides should always point to the "b" slides and your "b" slides will point to the "c" slides. Your hyperlinks on "back button" on "a" slides should be "previous slide" and on the "c" slides should be "last slide viewed" and on "h" slides should be "first slide" (use 'action' to set this instead of 'hyperlink').
It takes a while to work through, but it can be done.