Вы находитесь на странице: 1из 3

Sub ExportText()

Dim oPres As Presentation


Dim oSlides As Slides
Dim oSld As Slide 'Slide Object
Dim oShp As Shape 'Shape Object
Dim iFile As Integer 'File handle for output
iFile = FreeFile 'Get a free file number
Dim PathSep As String
Dim FileNum As Integer
#If Mac Then
PathSep = ":"
#Else
PathSep = "\"
#End If
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
FileNum = FreeFile
'Open output file
' NOTE: errors here if file hasn't been saved
Open oPres.Path & PathSep & "AllText.TXT" For Output As FileNum
For Each oSld In oSlides 'Loop thru each slide
For Each oShp In oSld.Shapes 'Loop thru each shape on slide
'Check to see if shape has a text frame and text
If oShp.HasTextFrame And oShp.TextFrame.HasText Then
If oShp.Type = msoPlaceholder Then
Select Case oShp.PlaceholderFormat.Type
Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
Print #iFile, "Title:" & vbTab & oShp.TextFrame.TextRange
Case Is = ppPlaceholderBody
Print #iFile, "Body:" & vbTab & oShp.TextFrame.TextRange
Case Is = ppPlaceholderSubtitle
Print #iFile, "SubTitle:" & vbTab & oShp.TextFrame.TextRange
Case Else
Print #iFile, "Other Placeholder:" & vbTab & oShp.TextFrame.
TextRange
End Select
Else
Print #iFile, vbTab & oShp.TextFrame.TextRange
End If ' msoPlaceholder
End If ' Has text frame/Has text
Next oShp
Next oSld
'Close output file
Close #iFile
End Sub
Where in PPT do I put the code?
Here's how you use VBA code in PowerPoint. First, a bit of prep work to make sur
e your security settings don't get in the way:
Open a PowerPoint presentation.
Set Macro Security to Medium or lower. If Security's set higher, PowerPoint disa
bles your macros when you open the file that contains them. With security set to
Medium, PowerPoint asks whether to enable macros when you open a file that cont
ains them.
PowerPoint 2003 or previous: Choose Tools, Macro, Security and set security to M
edium.
PowerPoint 2007: Click the Office button (the great big circular thing, upper le
ft of the PPT screen), click PowerPoint options at the bottom of the menu-like t
hing that appears, click Trust Center on the left of the PowerPoint Options dial
og box, click Trust Center Settings on the Trust Center dialog, click Macro Sett
ings on the left of the dialog then choose Enable All Macros. Whew. Close any op
en dialog boxes.
PowerPoint Mac: You don't need to do anything about macro security but it's a go
od idea to make sure that it's enabled. Choose PowerPoint, Preferences, General
and use the "enable macro virus protection" checkbox to turn the macro warning o
n.
Start the VBA editor
PowerPoint 2003 or previous: Press ALT+F11 to start PowerPoint's VBA editor. Or
choose View, Toolbars, Visual Basic to get shortcut buttons to the editor and fo
r running macros. Or choose Tools, Macro, Visual Basic Editor to start the edito
r.
PowerPoint 2007: Press ALT+F11 to start the VBA editor. Or click the Office butt
on, choose PowerPoint Options, click Popular and put a check next to "Show Devel
oper tab in Ribbon". Close the options dialog box, click the Developer tab then
click "Visual Basic" to start the editor.
Mac PowerPoint: Use View, Toolbars, Visual Basic then click the Visual Basic Edi
tor button on that toolbar.
In the VBA editor, make sure that your presentation is highlighted in the left-h
and pane. Choose Insert, Module from the menu bar to insert a new code module in
to your project (project = presentation in VBAspeak). Modules are one of the sev
eral "containers" that can hold VBA code.
If your code snippet already starts with "Sub XXX()" and ends with "End Sub", si
mply click in the new module you just inserted and paste in the code. Otherwise,
you'll have to type in "Sub XXX" (where XXX is the name you want to give the su
broutine (aka "macro"). When you press Enter, PowerPoint adds the parentheses an
d End Sub for you automatically. Then position the cursor between the Sub XXX an
d End Sub lines and paste in your code.
To make sure there are no serious syntax problems with the code, choose Debug, C
ompile from the menu bar. If there's a problem, you'll see a message explaining
(well ... explaining in a geeky, obtuse way that usually won't make any sense to
you) what VBA doesn't like about the code. Click OK and the problem line will b
e highlighted for you. Fix it and compile again until you get no error messages.
Now click the Run button (a right-facing arrowhead icon), choose Run, Run Sub/Us
er Form from the menu bar or press F5 to run your code.
Once your code's working properly, you can run it directly from within PowerPoin
t without having to start the VBA editor. Choose Tools, Macros, Macros to get a
list of available macros ( = subroutines, remember?) in the current presentation
. Highlight the one you want to run and click Run (or simply doubleclick the one
you want). You can also view and run macros from other open presentations; choo
se the presentation where your macro is stored from the Macros In dropdown listb
ox.

Вам также может понравиться