Microsoft KB Archive/236626

= PPT97: Sample Code to Batch Import Serially Named Graphics Files =

Article ID: 236626

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft PowerPoint 97 Standard Edition

-



This article was previously published under Q236626



SUMMARY
This article contains the sample code for a Visual Basic for Applications (VBA) macro that will import a group of sequentially-numbered graphics files. For example, if you have a group of files with names such as File001.bmp, File002.bmp, File003.bmp, and so forth, this macro can import all of them at once.

This macro creates one new slide for each image, and sets the background fill of the slide to that particular image.



MORE INFORMATION
To use this macro, the following conditions must be true:
 * 1) You are in Slide view when you run the macro.
 * 2) Your individual files have three-digit numbers.
 * 3) You know that path to the files, and how many of them there are.
 * 4) You know the names of the files

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

Sub BatchImport ' ' Declare the variables ' Dim strPath As String Dim strPrefix As String Dim strSuffix As String Dim iNumberofFiles As Integer Dim iCounter As Integer Dim strFilename As String

' Get the name of the path and the constant prefix to the file names

strPath = InputBox _ ("What is the path to your files (include the trailing backslash)?") strPrefix = InputBox("What is the prefix of your file name?") strSuffix = InputBox _ ("What is the file extension (including the period)?")

' Find out how many files there are total

iNumberofFiles = InputBox("How many files are there?") ' If your files start numbering at 001 instead of 000, comment out ' The following line:

iNumberofFiles = iNumberofFiles - 1

' Begin the loop. The number of times this loop repeats depends on ' how many files you told it there were.

For iCounter = 0 To iNumberofFiles

' Build the name of the file to import. ' This logic figures out how many zeroes to use. If iCounter < 10 Then _ strFilename = strPath & strPrefix & "00" & iCounter & strSuffix If iCounter > 9 And iCounter < 100 Then _ strFilename = strPath & strPrefix & "0" & iCounter & strSuffix If iCounter > 99 Then _ strFilename = strPath & strPrefix & iCounter & strSuffix ' This Msgbox is here for debugging purposes. It shows you what ' file name it thinks you are importing. Once you get your code ' running, you can delete the messagebox. MsgBox strFilename 'Creates a new slide. It is using the Title Only autolayout. _   If you want a different layout, change the next line. ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides. _   Add(Index:=2, Layout:=ppLayoutTitleOnly).SlideIndex 'Sets the background picture to be equal to the current _ strFilename With ActiveWindow.Selection.SlideRange .FollowMasterBackground = msoFalse .DisplayMasterShapes = msoTrue With .Background .Fill.Visible = msoTrue .Fill.ForeColor.RGB = RGB(255, 255, 255) .Fill.BackColor.SchemeColor = ppAccent1 .Fill.Transparency = 0# .Fill.UserPicture strFilename End With End With Next End Sub For example, suppose you had a series of fifty files in a folder called C:\Images. These files have the naming convention of Img000.jpg, Img001.jpg, Img002.jpg, and so forth through Img049.jpg. When you run the macro you will provide the following answers to the four questions it asks:


 * C:\images\
 * 1) img
 * 2) .jpg
 * 50

Once you answer the questions, PowerPoint creates fifty slides (using the Title only layout) and changes the backgrounds of these fifty slides to match the fifty images.

Additional query words: bulk importer set as background ppt powerpnt ppt97 97 8.0 ppt8 vba example howto how to pictures

Keywords: kbhowto kbinfo kbprogramming KB236626

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.