Click here to Skip to main content
13,144,300 members (34,626 online)
Click here to Skip to main content
Add your own
alternative version

Stats

4.1K views
83 downloads
2 bookmarked
Posted 19 Jul 2016

An Autoit Script to Generate a PowerPoint Presentation from MSWord Document

, 19 Jul 2016
Rate this:
Please Sign up or sign in to vote.
A program for generating a PowerPoint presentation from a structured MSWord document

Introduction

This program is an AutoIt[1] script for generating a PowerPoint presentation from a structured MSWord document, it is also an example of how we can work with COM (Component Object Model) objects in particular, in this case, the use of COM objects for MSWord and PowerPoint.

For those interested in the topic, I have already addressed AutoIt and COM technology in an earlier article: An Autoit script to extract data from a MSWord document and send them to an Internet application.

The article carries the following topics:

  • How to access the MSWord documents
  • How to extract the data
  • How to create, and possibly start, a presentation

Every document which can be read by MS Word can generate a presentation, provided that it is structured in chapters and the styles are Heading 1, Heading 2, Heading 3 and possibly Title.

MSWord Document

Word exposes the object for manage a document; this object that can contain the document if it is loaded, is a set of methods and collections like paragraphs, tables, comments, styles, etc.

The application deals with paragraphs that have text styles and heading styles, those names are in the language of installation: for example the heading style in Italian is Titolo; in the fragment below, a method for getting the local name[2].

...
$fl = "C:\D\Condor\Attività\CourseInformatique\JavaScriptCourse.odt"
$oDoc = ObjGet($fl)	; open an existing MSWord document
...
; for to be independent from local language we must obtain the local name using a key of the style:
$title = $oDoc.Styles(-63).NameLocal
$heading1 = $oDoc.Styles(-2).NameLocal
$heading2 = $oDoc.Styles(-3).NameLocal
$heading3 = $oDoc.Styles(-4).NameLocal
$normal = $oDoc.Styles(-1).NameLocal	
$BodyText = $oDoc.Styles(-67).NameLocal

PowerPoint

The entire Microsoft PowerPoint application is the object Application essentially a collection of Presentations and slides.

Application
    Presentations (collection of presentations)
        Presentation
            Slides (collection of slides)
                Slide

A slide is generated by adding a new slide to a presentation, with a specific layout:

Global $oPPT = ObjCreate("PowerPoint.Application")
$PPT = $oPPT.Presentations.Add(True) ; add a Presentation
...
$oSlide = $PPT.Slides.Add($index, $ppLayoutText)	; add a slide
...

Every layout has a set of shapes which can contain data, charts, tables, etc.; in the program I used a layout with title and subtitle and a layout with title and text.

The aesthetic of presentation can be done by setting some properties of SlideMaster object or directly on a particular slide:

$PPT.SlideMaster.Background.Fill.foreColor.RGB = 51200   ; green
$PPT.SlideMaster.Background.Fill.oneColorGradient(3, 1, 1)

Executing the Program

The program needs AutoIt v3.3.14.2; it starts with a form[3] that asks the name of the document, the possibly styles involved in the build of the slides, the action at the end and a very simple personalisation.

Building Rules

Below are the simple rules for creating a presentation:

  • Every title and heading 1 generates a slide with a list of his heading 1 or heading 2 respectively
  • Every title, heading 1 and heading 2 generates a slide with content, where the content is the first paragraph after title, heading 1 or heading 2, having style Normal or Standard
  • For title and heading 1 if the above text can’t be found, the slide is suppressed; for heading 2 are inserted the heading 3 pertaining

Final Actions

The program in addition to saving the presentation (file name body plus .ppt) and possibly save a .pdf copy, can start the presentation and wait for his term using the event SlideShowEnd:

Global $endPresentation = false
Global $oPPT = ObjCreate("PowerPoint.Application")
...
$EventObject = ObjEvent($oPPT, "PWTevent_") 	; Start receiving Events
...
$PPT.SlideShowSettings.Run() ; start the slide show
While Not $endPresentation   ; wait end of presentation
	Sleep(10)
Wend
...
Func PWTevent_SlideShowEnd($pres)
	$endPresentation = True
EndFunc   ;==>PWTSlideShowEnd

An Enhancement

There is no need to adapt the Word document if it is correctly structured and one follows the good practice to specify in the first paragraph of each chapter its contents, however the program offers the opportunity to intervene on the presentation with simple operation on document:

  • Bookmarks a set of contiguous paragraphs
  • Add comments

In the first case, the bookmark name must be the name of the heading concerned, in the second the comment must be associated at the heading. Below is the fragment of program that creates a dictionary from bookmarks and comments, and how this is used.

...
Global $commentsDict = ObjCreate("Scripting.Dictionary") ; Create a Scripting Dictionary
For $comment In $oDoc.Comments
	$commentsDict.Item($comment.scope.text) = $comment.range.text
Next
For $bookmark In $oDoc.bookmarks
	$commentsDict.Item($bookmark.name) = $bookmark.range.text
Next
...
If $commentsDict.Exists($parag) Then
	$oSlide.Shapes(2).TextFrame.TextRange.Text = $commentsDict.Item($parag)
EndIf
...

Notes

  1. ^AutoIt is a free-ware BASIC-like scripting language, an alternative to PowerShell, designed in origin for automating the interaction with Windows GUI. AutoIt can run on Windows interpreted or compiled.
    It comes with many libraries that enable, among other things, access COM objects and create graphical interfaces.
  2. ^Thanks to Lene Fredborg, DocTools, www.thedoctools.com.
  3. ^The form is created by my utility formGen that you can find in this site.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Member 4206974
Software Developer Condor Informatique
Italy Italy
Computer literacy (software) : Languages: PHP, Javascript, SQL Autoit,Basic4Android; Frameworks: JOOMLA!
Teaching/Training skills on Office, WEB site development and programming languages.
Others : WEB site development.
UNDP Missions
feb – may 2003 Congo DR Bukavu: ground IT computer course
nov 2003 Burundi Bujumbura: Oracle Data Base course
feb 2005 Burundi Bujumbura: JAVA course
mar 2005 Mali Kati: MS Office course
oct 2006 Mali Kati: MS Office course
jun 2006 Burkina Faso Bobo Dioulasso: MS Office course
jun 2007 Burkina Faso Bobo Dioulasso: MS Office course
may 2007 Argentina Olavarria hospital: Internet application for access to medical records
apr 2008 Burkina Faso Ouagadougou: MS ACCESS and dynamic Internet applications
jun 2008 Niger Niamey: analysis of the computing needs of the Niamey hospital
may 2009 Burkina Faso Ouagadougou: MS ACCESS and dynamic Internet applications
oct 2010 Niger Niamey: analysis of the computing needs of the Niamey hospital (following)
Region Piedmont project Evaluation
mar 2006 Burkina Faso, Niger
mar 2007 Benin, Burkina Faso, Niger
sep 2008 Benin, Burkina Faso, Niger
Others
feb 2010 Burundi Kiremba hospital: MS Office course
feb 2011 Congo DR Kampene hospital: MS Office course

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Member 1236439021-Jul-16 21:18
memberMember 1236439021-Jul-16 21:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 20 Jul 2016
Article Copyright 2016 by Member 4206974
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid