You are on page 1of 6

Computers in Radiology

Chris Sistrom1
Janice Honeyman-Buck

A Simple Method for Importing

Multiple Image Files into
OBJECTIVE. We developed a method for automatically inserting a large number of images into a PowerPoint presentation document.
CONCLUSION. We designed, tested, and now routinely use a simple macro program for
importing all images contained in a single directory into a PowerPoint presentation. The complete text of the macro code is included in this article, and readers are encouraged to experiment with it.

Received October 23, 2003; accepted after revision

November 20, 2003.
C. Sistrom received funding from a General Electric
Association of University Radiologists Research
Fellowship from July 2000 through June 2003.

Both authors: Department of Radiology, University of

Florida, PO Box 100374, Gainesville, FL 32610. Address
correspondence to C. Sistrom.
AJR 2004;182:15911596
American Roentgen Ray Society

AJR:182, June 2004

everal authors have recently described techniques for acquiring,

optimizing, and storing radiologic
images for teaching and publication using PCs
and common software [18]. Once they are
finished, such images are often incorporated
into slide presentation software programs, of
which the most ubiquitous is Microsofts PowerPoint program, a part of their Office Suite.
The process of bringing images into PowerPoint and preparing the resulting presentations for effective teaching has been
described in detail [913]. Importing the picture files into a presentation can take a considerable amount of time, especially when
many images are required. Another time-consuming task is scaling and centering the images once they have been added to slides.
Scaling is particularly troublesome when the
image is larger than the slide.
We have developed a short program using
the Visual Basic for Applications language that
takes advantage of the macro functionality
built into all Microsoft Office products. Our
program automates the process of importing
multiple images into a PowerPoint presentation. The only prerequisites are that the image
files be in one of several standard formats and
that they reside in a single directory. During

the import process, each image is optimally

centered and scaled on a separate slide. In this
article, we briefly describe the function and
use of the macro program and also give a complete listing of it so that readers can use it
themselves. The software is also available for
download from a Web site.

How the Macro Works

Once activated, the macro requests a directory location from the user. It then searches
through the entire directory and obtains the
name the files. Each file is tested to determine
if it contains an image in one of five common
formats, using the three-letter file extension as
its criterion. The five formats include tagged
image file format (.tif), PC paintbrush (.pcx),
bit-mapped graphics format (.bmp), .gif, and
.jpg. If a file has one of these extensions, the
image it contains is placed on a new slide and
added to the presentation.
Before moving to the next file, the program
code centers and sizes the image to make it as
large as possible and still fit on the slide. Large
images are scaled down and small images are
scaled up as needed. PowerPoint stores variables representing the width, height, and absolute position for all shapes (including images)


Sistrom and Honeyman-Buck

Fig. 1.Macro dialogue box in Microsoft PowerPoint. Macro

name (arrowhead) has been entered. To add macro code, click
Create (arrow).

in each slide, which makes it easy to compute

appropriate scale and position factors and apply them to the image. These calculations preserve the height-to-width relationshipthe
aspect ratioof the original image. When the
process is finished, a dialogue box is displayed
listing the total number of files and the number
of images imported.

Fig. 2.Visual Basic editing window in Microsoft PowerPoint after creating

macro called Getpix. Copy macro code to blank line (arrow) above End Sub.

ied from Appendix I of the online article)

should be pasted in the blank line above End
Sub. Then select File > Close and return to
Microsoft PowerPoint. Before importing any
images or creating other slides, select File >
Save As and save a blank presentation containing the macro for future use in one of your
Using the Macro

Installing the Macro into Your

PowerPoint Presentation

We have included the entire macro as Appendix I of this article. To keep it as compact
as possible, we have removed comment lines
and show only the program itself. To obtain an
electronic copy of the code, go to the AJR web
site and look up the full text of this article.
Scroll down to Appendix I and copy the text
that appears between the dashed lines. Do this
by highlighting the text with your mouse and
clicking Edit > Copy. Next, open Microsoft
PowerPoint and select Tools > Macro >
Macros. In the top of the resulting dialogue
box, type the name of the macro (Fig. 1). We
used the name Getpix. Then click on Create and another window will open (Fig. 2).
This is the Visual Basic Editor. You should see
the following text in the editing window:

Once the macro has been created in a PowerPoint presentation file, using it is fairly simple. Select Tools > Macro > Macros, and
highlight the name of the macro (e.g., Getpix
as in Fig. 3). After the Run button is clicked,
the macro activates and displays a dialogue
box that asks for the location of the directory
containing the images to be imported. Type the

directory path (C:/Temp/Pix1/) in our example

and click the OK button (Fig. 4). The macro
imports all the images into the chosen directory, places each one on a separate slide, and
centers and scales them to fit. The slides are
ordered in an alphabetic sequence that is based
on the file names of the source images. A completion dialogue box (Fig. 5) gives results of
the operation and displays the source directory,
the total number of files, and the number of
slides created. The macro may be executed
again, and additional images will be added to
the end of the presentation.
One convenient way to use the program is to
create and save a blank PowerPoint presentation
file (e.g., call it Blank.ppt) that contains the
macro. Set up the master slide template in this
blank presentation to reflect your individual

Sub Getpix()
Macro created mm/dd/yyyy by xxx zzzz
End Sub,
where mm/dd/yyyy is the current date and xxx
zzzz is the users name. If a different name for
the macro was used, it will show up in the first
line instead of Getpix. The macro text (cop-


Fig. 3.Macro dialogue box in Microsoft

PowerPoint. Macro called Getpix has already been installed. To activate it, click
mouse once on macro name to highlight and
then click Run (arrow).

AJR:182, June 2004

Computers in Radiology

Fig. 4.Prompt displayed by PowerPoint (Microsoft) macro at run

time asks for path to image source directory. Name and path (C:/
Temp/Pix1/) have already been typed. Program will activate when
Run is clicked.

preferences for slide background and text properties. To start a new working presentation, simply open Blank.ppt and run the macro. Before
importing the images, select File > Save As and
specify a new location and name for your presentation. After you click Save, the file name
at the top of the PowerPoint window will change
to reflect the newly chosen name. The blank presentation will remain unchanged and ready for
the next session.
Presentations can be edited to add text
slides between image slides.

Deleting the Macro

A minor drawback of using macros in

PowerPoint presentations is that when they
are opened, an extra dialogue box may appear (Fig. 6). It warns that macros can sometimes be harmful and offers to disable them.

Some particularly conservative antivirus programs may identify a presentation containing

a macro as being potentially compromised.
The best way to avoid this message is to delete the macro from your working presentation after all the images have been imported.
To do this, select Tools > Macro > Macros
and highlight the name of the macro (e.g.,
Getpix in our example). Then click Edit
and a new window will open. The upper left
corner will show a sub window called
ProjectVBAProject (Fig. 7). Highlight
Module1, right click, and select Remove
Module1. Answer No to the dialogue box
that appears, and the macro will be removed.
Next, select File > Close and return to Microsoft PowerPoint. If the presentation is
saved at this point and then reopened, it will
activate and display the slides without the
initial warning dialogue box.

Fig. 6.When file containing macro is opened, PowerPoint

(Microsoft) may display dialogue box that warns about possible
harmful effects and offers to disable any macros in file. For our
macro to work, Enable Macros must be clicked.

AJR:182, June 2004

Fig. 5.Prompt displayed by PowerPoint

(Microsoft) macro after completion lists
source directory, total number of files, and
number of slides created. Presentation
may be edited after OK is clicked.

Alternate Solutions

In his article titled Getting Images into PowerPoint, Schreibman [12] briefly notes an enhancement for PowerPoint 2000 that is
available from Microsoft. We accessed the
Web site listed in the article text [14] and
downloaded and installed the program (a
photo album add-in for PowerPoint). We used
the software to import the same set of images
we had previously used to test our macro. The
Fit To Slide option was chosen. The resulting PowerPoint presentation was identical to
one created by our macro in every respect.
Readers are encouraged to experiment with the
Microsoft photo album solution. It has a
graphic interface to browse for image files, allows preview of images, and permits selection
of individual images. However, the photo album addin is specific to the Office 2000 version of PowerPoint. Also, the photo album

Fig. 7.Window displayed after clicking on Edit in PowerPoint (Microsoft) macro dialogue box (Fig. 3). To remove code from current presentation, highlight line called Module1 (arrows), right click with mouse,
and select Remove Module1 from resulting pick list. Answer No to
subsequent dialogue box that offers to save module.


Sistrom and Honeyman-Buck

feature is an extension to the PowerPoint program itself and must be installed on each computer before it is used. Our macro does not
require installing any new software and is
portable in the sense that a blank presentation file containing the code can be copied to
any computer, and the image import function
will be immediately available. We have confirmed that the macro functions identically on
numerous computers running the Windows 97,
Windows 2000, Windows XP, and Macintosh
versions of PowerPoint.
One group has developed a teaching file
system with Microsoft Visual C++ and a Visual FoxPro database [15]. This system uses
programming techniques similar to those in
our macro to inject multiple images from
the teaching file into a PowerPoint presentation. These authors also stressed that this feature would save considerable time over the
conventional method of inserting images
onto individual slides in a presentation. The
concept of complete integration of a teaching
file database with presentation software is
powerful, and we are working toward this
with our own departmental electronic teaching file system. In the meantime, our approach offers a method for at least partial
automation of the process that should be useful to all readers.


The most obvious source of problems will

be any errors made while creating the macro.
The macro is a computer program and must
be entered or copied accurately in exactly the
correct sequence. If the macro is entered incorrectly, a variety of error messages may result when it is run. For the code to function
correctly, the Microsoft Office installation
must have included all the relevant image
import filters. These filters are common to
the whole suite of Microsoft Office programs
and will be present if the typical configuration option was chosen during the initial Office installation.
The default security behavior of PowerPoint
pertaining to macros has already been mentioned: The Medium security setting causes
display of a warning dialogue box at startup
(Fig. 6) when the presentation contains a userdefined macro. With High security, PowerPoint opens a macro-containing presentation
without any warning dialogue box. However,
if Tools > Macro > Macros is selected, the
Run button will be inoperable. To correct
this, click Tools > Macro > Security and se-


lect the Medium setting. After you exit and

restart PowerPoint, answer Enable Macros
in the warning dialogue box and proceed to
use the macro.
If your current Microsoft Office software
does not include one or more of the graphics
import filters, PowerPoint may attempt to automatically install the relevant filter when the
macro encounters an unrecognized image
type. A dialogue box will appear indicating the
need for a filter, and the user may be prompted
to insert the original program disk (usually a
CD-ROM). Updating the Microsoft Office installation manually may require running the
Office setup program again. In newer versions
of Windows (98 or later), this operation is performed through the Control Panel and its
Add/Remove Programs function. Older versions of Windows may require inserting an Office installation CD-ROM and running setup
from the CD-ROM. After activating the setup
program, select the Add/Remove Features
option, select Converters And Filters >
Graphics Filters, and make sure that all the relevant graphics import filters (labeled BMP,
JPEG, PCX, GIF, and TIF) are active by verifying that they have a check mark next to
them. Then follow the onscreen directions to
update the installation.
One more potential barrier to proper functioning of our macro is somewhat esoteric. The
macro draws on references, which are ancillary files included in most standard Microsoft
Office installations. They are external to the
main PowerPoint program and are needed to
enable the functions coded in macros. We experimented with various versions of PowerPoint and found that three references must be
active: Visual Basic for Applications, Microsoft PowerPoint X.Y Object Library, and

Microsoft Office X.Y Object Library. X.Y is

the current version of the Microsoft software
your computer is running. For example, X.Y =
9.0 at our installation, but it may be different
for other computer systems.
To look at the references, open a presentation containing the macro and select Tools >
Macro > Macros, highlight the macro name,
and click Edit. When the Visual Basic Editor
window opens, select Tools > References,
and the dialogue box shown in Figure 8 should
be displayed. One can scroll down through the
list and click the boxes next to the relevant entries if they are not already checked. Be careful
about clearing the checks from any other
boxes because they may be providing functionality needed for other features that your
particular Office installation is using.


Our program lacks the ability to add multiple images to a single slide. This feature is not
needed for most purposes. In fact, crowding
multiple images onto one slide may make it
much harder for the audience to see the radiologic findings. Some may believe that putting
multiple images on each slide would reduce
the file size of the resulting presentation. This
is not the case because imported images are
kept in their entirety with scaling tags that are
added to cause them to be displayed as specified. We find it preferable to make the points
about cases and findings in our text slides and
then illustrate the points with full-sized images
augmented with annotations such as arrows.
Multiple images can be placed on a single
slide during the editing of the presentation content after the images have been imported. The
macro code can also be modified to scale images

Fig. 8.Dialogue box displayed after selecting Tools > References

from Visual Basic window (Fig. 7)
during macro editing shows that
three required objects (Visual Basic
for Applications, Microsoft PowerPoint 9.0 Object Library, and Office
9.0 Object Library) are checked,
which indicates that they are active.
Version number for Microsoft Office
(here, version 9.0) will vary depending on your software.

AJR:182, June 2004

Computers in Radiology
to one half or one quarter the size of a slide,
which would make it easy to show several images at once. One of the reasons that we are including the full code of the macro is to encourage
readers to modify it to suit their individual needs.
The method of specifying the image input directory is rudimentary and does not use the
graphic file selection methods available in Windows. The user must accurately type the complete path to the image file directory. Also, we
have not provided an option to preview or select
individual images for the import directory.
These features could have been written into our
macro. However, the code would have been
much longer, more complex, and version-specific. We decided to keep the program simple to
reduce the possibility of errors. More functionality requires additional customization of the
PowerPoint installation. Users may already face
challenges in getting the existing code to work
properly on their particular computers.

Appendix I contains the complete text of

the macro. Detailed instructions are provided in the text for copying the code from

the online version of this document on the

AJR Web site and installing it in a blank
PowerPoint presentation.
We have described how to use the macro
and given troubleshooting advice for common problems that might arise. We have also
placed blank PowerPoint presentation files
with the macro already installed on an Internet server [16] for any interested readers
to download. To obtain them, simply
browse to where you will find download
links for the macro text and blank presentation files in formats for various versions of
PowerPoint. We hope that interested readers
will use the program, modify it as needed,
and pass it on to their colleagues.
1. Caruso RD, Postel GC. Image editing with Adobe
Photoshop 6.0. RadioGraphics 2002;22: 9931002
2. Caruso RD, Postel GC. Image annotation with Adobe
Photoshop. J Digit Imaging 2002;15:197202
3. Corl FM, Garland MR, Lawler LP, Fishman EK. A
five-step approach to digital image manipulation for
the radiologist. RadioGraphics 2002;22: 981992
4. Taylor GA. Initial steps in image preparation.

AJR 2002;179:14111413
5. Taylor GA. Removal of dust and scratches from
electronic image files. AJR 2003;180:15331536
6. Taylor GA. Sharpening the image. AJR 2003;
7. Taylor GA. Color correction and automating repetitive tasks. AJR 2003;181:383386
8. Taylor GA. Improving image contrast. AJR 2003;
9. Daffner RH. On improvement of scientific presentations: using PowerPoint. AJR 2003;181:4749
10. Dreyer KJ. Using Microsoft PowerPoint for electronic presentations. RadioGraphics 2001;21:
11. Schreibman KL. Hello, and two great tricks. AJR
12. Schreibman KL. Getting images into PowerPoint. AJR 2001;177:12711272
13. Willing SJ. Getting images into PowerPoint. AJR
14. Microsoft Download Center. Microsoft Web site.
Available at: Accessed March 19, 2004
15. Frank MS, Schultz T, Dreyer K. Integrating digital
teaching-file systems with off-the-shelf presentation software to facilitate speaker-led conferences. J
Digit Imaging 2001;14[suppl 1]:98101
16. Authors Web site. Avialable at: http://

Appendix 1 appears on the next page

AJR:182, June 2004


Sistrom and Honeyman-Buck

APPENDIX I. PowerPoint (Microsoft) Macro Program to Import Multiple Images

Here is the exact text of the macro. Highlight all the text below this paragraph, copy, and paste into the PowerPoint Macro > Create window (Fig. 1).
Dim File_Cnt, Sld_Cnt, Sld_Pos As Long
Dim Source_Dir, File_Name, Path_Complete, Ext_3, Ext_4 As String
Dim sldNewSlide As Slide
Dim shpPicture As Shape
Dim tmpWidth, tmpHeight, W_H_pic, W_H_sld, lngSldHeight, lngSldWidth As Double
File_Cnt = 0
Sld_Cnt = 0
Source_Dir = InputBox(Location of images, End with / (: for Macintosh), Image Directory)
If Len(Source_Dir) = 0 Or IsNull(Source_Dir) Then GoTo No_Input_Exit
On Error GoTo No_Input_Exit
File_Name = Dir(Source_Dir, vbNormal)
While Len(File_Name) <> 0
File_Cnt = File_Cnt + 1
Ext_3 = UCase(Right(File_Name, 3))
Ext_4 = UCase(Right(File_Name, 4))
If Ext_3 = TIF Or Ext_3 = GIF Or Ext_3 = JPG _
Or Ext_4 = JPEG Or Ext_3 = PCX Or Ext_3 = BMP Then
Sld_Cnt = Sld_Cnt + 1
Path_Complete = Source_Dir & File_Name
Sld_Pos = ActivePresentation.Slides.Count
Set sldNewSlide = ActivePresentation.Slides.Add(Index:=Sld_Pos + 1, _
Set shpPicture = sldNewSlide.Shapes.AddPicture(FileName:=Path_Complete, _
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _
Left:=0, Top:=0, Width:=100, Height:=100)
shpPicture.LockAspectRatio = True
shpPicture.ScaleHeight 1#, msoCTrue
shpPicture.ScaleWidth 1#, msoCTrue
lngSldWidth = ActivePresentation.PageSetup.SlideWidth
lngSldHeight = ActivePresentation.PageSetup.SlideHeight
tmpWidth = shpPicture.Width
tmpHeight = shpPicture.Height
W_H_pic = tmpWidth / tmpHeight
W_H_sld = lngSldWidth / lngSldHeight
If W_H_pic >= W_H_sld Then
shpPicture.Width = lngSldWidth
shpPicture.Height = lngSldHeight
End If
tmpWidth = shpPicture.Width
tmpHeight = shpPicture.Height
shpPicture.Top = (lngSldHeight - tmpHeight) / 2
shpPicture.Left = (lngSldWidth - tmpWidth) / 2
End If
File_Name = Dir()
MsgBox Input Directory= & Source_Dir & Chr(13) & Chr(10) & _
Total Files= & File_Cnt & Slides Added= & Sld_Cnt, vbOKOnly, Results


AJR:182, June 2004