WORKING WITH MACROS

WHAT IS A MACRO ???

Have you ever found yourself performing the same set of tasks over and over and over again when creating a PowerPoint presentation? Even if the tasks are simple and straightforward, repeating them continuously is both boring and time consuming.  

One way to simplify the performance of these tasks, and save a lot of time in the process, is to use macros.

A macro is basically a custom command, or shortcut, that performs a series of actions.  
 
A macro is a series of commands to automate a repetitive task. The macro commands are recorded and assigned to a keystroke combination. 

This process is done by  the user of the program.


EXAMPLE-

Suppose a user have 50 PowerPoint presentations that all contain your company’s logo on the title slide. 
The only problem is that the company has decided to change its logo and now wants all of the presentations updated.  

Rather than going through each presentation and manually replacing the logo 50 times, user can create a macro that will update all of the presentations .

Begin the macro creation process by deciding what task to automate. Assign the macro a name and then the program records each keystroke needed to complete this task. Once the recording  is finished the macro is saved for later use .

VBA-

PowerPoint and other Microsoft Office programs comes with VBA, Visual Basic for Applications. 
VBA is an implementation of Microsoft’s event-driven programming language Visual Basic 6 and let you run scripts and macros in the popular Microsoft Office applications.

VBA enables building user defined functions, automating processes and accessing Windows API and other low-level functionality through dynamic-link libraries (DLLs). 

Office for Mac also supports VBA since PowerPoint 2008 and other Microsoft applications such as Microsoft MapPoint and Microsoft Visio have support, too.

By using VBA user can write or run their own Macros and PowerPoint Scripts to make richer PowerPoint presentations with custom application code.

Accessing the Developer Tab


To work with macros in PowerPoint 2007, user will need to be able to access the Developer tab on the PowerPoint ribbon. 

If that tab is not visible on PowerPoint screen, it can be added in a couple of easy steps.

Enable the Developer Tab

Step 1
 
In PowerPoint, right-click the "Quick Access Toolbar," which is in the upper left corner next to the Publisher icon. Select "Customize the Ribbon."
 
Step 2
 Select "All Tabs" under Customize the Ribbon on the right.
Step 3
 Select the Developer Tab check box in the list of tabs available. Click "OK." The Developer tab appears on the PowerPoint Ribbon.

 

Create a New Macro

Step 1
 Go to the "Developer" tab of the Ribbon. Click the "Macros" button in the Code group to open the Macro dialog box.
 
Step 2
 Type a name that describes the macro into the Macro Name box. For instance, to create a macro that will change the format of  slide titles, enter "FormatSlideTitles" into the Macro Name box.
 
Step 3
 Click the "Create" button to open the Visual Basic Editor.
Step 4
 Enter the VBA code to apply.

For instance, for creating a macro to format slide titles, enter the following code:

Dim s As Slide Dim shp As Shape
For Each s In ActivePresentation.Slides For Each shp In s.Shapes If shp.Type = msoPlaceholder Then With shp .Top = 8 .TextFrame.TextRange.Font.Name = "Cambria" .TextFrame.TextRange.Font.Size = 26 End With End If Next shp Next s
End Sub


Step 5
 Go to the "File" tab and select "Close and Return to Microsoft PowerPoint" or press "Ctrl-Q" to save the macro and return to your presentation.


Add a Macro Button to the Quick Access Toolbar

Step 1
 Right-click the "Quick Access Toolbar," which is in the upper left corner next to the Publisher icon. Select "Customize the Ribbon."

Step 2
 Select "All Commands" in the Choose Commands From list.

Step 3
 Select "Macros" from the list of commands. Click the "Add" button and click "OK."

Step 4
 Click the "Macros" button on the Quick Access Toolbar and select the macro you wish to run.

EXAMPLES OF MACRO CODES -

Picture Format in 2007

2007 Offers great picture tools. If user have soft shadows, borders etc set up on one picture this code will set all pictures to the same format. ONLY FOR 2007!

Select the pic that is formatted and run!

Sub All_Pics()
'this is for 2007 only
Dim osld As Slide
Dim oshp As Shape
If ActiveWindow.Selection.Type <> ppSelectionShapes Then Exit Sub
Set oshp = ActiveWindow.Selection.ShapeRange(1)
ActiveWindow.Selection.ShapeRange(1).PickUp
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.Type = msoPicture Then oshp.Apply
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture Then oshp.Apply
End If
Next oshp
Next osld
End Sub

Full slide Images

Sub Pic_Size()
'resize selection to full page
'note may distort image
Dim oshp As Shape
If ActiveWindow.Selection.Type <> ppSelectionShapes Then Exit Sub
Set oshp = ActiveWindow.Selection.ShapeRange(1)
With oshp
.LockAspectRatio = False
.Height = ActivePresentation.PageSetup.SlideHeight
.Width = ActivePresentation.PageSetup.SlideWidth
.Left = 0
.Top = 0
End With
End Sub