Header
PowerPoint tips, hints and tutorials that will change your presentations for ever!

INDEX

IF you have Digg or Del.icio.us accounts save us here.

Digg!

delicious Del.icio.us

Jigsaws
Sounds
Video
Custom Shows
vba code
NaviSlides
Games for teachers
Bullets
Triggers
Security
Flash Cards
Multiple Instances
PowerPoint 2007
Mail Merge
Random events
Animation
Hyperlinks
Set spellcheck language


Home buttonTutorial buttonContact buttonProducts button


Some vba Samples

If you haven't already read How to Use vba Code you should do this first.


Last Slide Viewed + 1

This code snippet is for use in Slide show mode ONLY. Copy and paste it to a module see How to use vba Code and then give an action button an action of Run > Macro > lastplus

Sub lastplus()
On Error GoTo errorhandler
With SlideShowWindows(1).View
.GotoSlide (.LastSlideViewed.SlideIndex + 1)
End With
Exit Sub
errorhandler:
MsgBox ("Sorry there's been an error!")
End Sub

The action button you make will return you to the slide AFTER the last slide viewed. Note that the on error statement is used because in the unlikly case of an error it sends the user to a "safe" message rather that the default possibility of debug the code. You do not want users playing with the code! The code will normally end at "exit sub" and never get to the message.


Change My Colour

This code will change the colour of any shape clicked in slide show mode. This is a good place to start adapting code. Adjust the R, G and B values (currently 255,0,0) to get the colour you want.

Sub changecol(oshp As Shape)
On Error GoTo errhandler
oshp.Fill.ForeColor.RGB = RGB(255, 0, 0)
Exit Sub
errhandler:
MsgBox "Sorry there's an error"
End Sub

Any shape that you want to click should be given an action setting of Run > Macro>changecol


Change Font for Whole Presentation

This vba will save your life when someone produces a presentation with different font styles and colours on every page and because they don't follow the Master you have to change each one individually. This vba will do the job in a tick!. You will need to change the values for font name, size and RGB values for title and body text and maybe set .bold and / or .italic to msotrue. Note only text in Placeholders is converted.

Sub allchange()
Dim osld As Slide, oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.Type = msoPlaceholder Then
'Title text change values as required
If oshp.PlaceholderFormat.Type = ppPlaceholderCenterTitle Or ppPlaceholderTitle Then
With oshp.TextFrame.TextRange.Font
.Name = "Arial"
.Size = 36
.Color.RGB = RGB(0, 0, 255)
.Bold = msoFalse
.Italic = msoFalse
.Shadow=false
End With
End If
If oshp.PlaceholderFormat.Type = ppPlaceholderBody Then
'Body text change values as required
With oshp.TextFrame.TextRange.Font
.Name = "Arial"
.Size = 24
.Color.RGB = RGB(255, 0, 0)
.Bold = msoFalse
.Italic = msoFalse
.Shadow=false
End With
End If
End If
Next oshp
Next osld
End Sub


UnBold

This code searches placeholders and textboxes in the presentation for BOLD text and un-bolds it

Sub unbold()
Dim osld As Slide
Dim oshp As Shape
Dim oTemp As TextRange
Dim i As Integer
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame.HasText Then
Set oTemp = oshp.TextFrame.TextRange
For i = 1 To Len(oTemp)
If oTemp.Characters(i).Font.Bold = True Then _
oTemp.Characters(i).Font.Bold = False
Next
End If
End If
Next oshp
Next osld
Set oTemp = Nothing
End Sub


 

Jump to a Random Slide

This is the code to jump to a random slide within a given range. Give an action button an action of Run > Macro > randjump to use it.

To generate the random number use this formula:

Number =Int((highest number in range - one less that lowest number)*rnd + lowest number in range)

eg For a number between 4 and 10

number = Int(10-3)*rnd+4) ---OR -- Int(7*rnd +4)

So here's the code to jump to a random slide between 4 and 10

Sub randjump()
randomize
Dim Inum As Integer
Inum = Int(7 * Rnd + 4)
ActivePresentation.SlideShowWindow.View.GotoSlide (Inum)
End Sub

Most people will tell you random slide choice can only be done with vba. If vba isn't suitable for your use look at random powerpoint slides without vba

See more vba samples here Table Format Copy and Selective Printing

 

 
 

Back to the Index Page

POWERPOINT BLOG

Articles on your favourite sport

Free Microsoft PowerPoint Advice, help and tutorials, Template Links
This website is sponsored by Technology Trish Ltd
© Technology Trish 2007
Registered in England and Wales No.5780175
PowerPoint® is a registered trademark of the Microsoft Corporation