How to change the background of a PowerPoint presentation with a visual basic script?
I’ll make my new PowerPoint "OS" soon, and I need a VB script, to change the background of all slides from the presentation.
The user gets a pop up window and he can change the original background to another picture. I’ve got PPT 2007. Is it possible to make this? Thanks for any answers ![]()
The following will do what you want, its tested on 2003.
Function ShowFileDialog(filtername As String, filter As String) As String
Dim dlgOpen As FileDialog
Dim result As String
Set dlgOpen = Application.FileDialog(Type:=msoFileDialogFilePicker)
With dlgOpen
‘Add a filter that includes GIF and JPEG images and make it the first item in the list.
.Filters.Add filtername, filter, 1
.AllowMultiSelect = False
If .Show = -1 Then
‘Step through each string in the FileDialogSelectedItems collection.
‘ There will only be one but this works better than a file open dialog for some reason.
For Each vrtSelectedItem In .SelectedItems
‘vrtSelectedItem is a String that contains the path of each selected item.
‘You can use any file I/O functions that you want to work with this path.
result = vrtSelectedItem
Next vrtSelectedItem
‘If the user presses Cancel…
Else
End If
End With
ShowFileDialog = result
End Function
Sub ChangeBackground()
‘
‘ Macro written 14/01/2010 by Nick
‘
Dim file As String
‘
‘ display a file selection dialog box
‘
file = ShowFileDialog("Images", "*.gif; *.jpg; *.jpeg")
If ActivePresentation.HasTitleMaster Then
With ActivePresentation.TitleMaster.Background
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Fill.BackColor.SchemeColor = ppAccent1
.Fill.Transparency = 0#
.Fill.UserPicture file
End With
End If
With ActivePresentation.SlideMaster.Background
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Fill.BackColor.SchemeColor = ppAccent1
.Fill.Transparency = 0#
.Fill.UserPicture file
End With
With ActivePresentation.Slides.Range
.FollowMasterBackground = msoTrue
.DisplayMasterShapes = msoTrue
End With
End Sub