PPT97: Sample Code to Batch Import Serially Named Graphics Files
ID: Q236626
|
The information in this article applies to:
-
Microsoft PowerPoint 97 For Windows
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:
- You are in Slide view when you run the macro.
- Your individual files have three-digit numbers.
- You know that path to the files, and how many of them there are.
- You know the names of the files
Microsoft provides programming examples for illustration only, without
warranty either expressed or implied, including, but not limited to, the
implied warranties of merchantability and/or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language being demonstrated and the tools used to create and debug
procedures. Microsoft Support professionals 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
needs. If you have limited programming experience, you may want to contact
the Microsoft fee-based consulting line at (800) 936-5200. For more
information about the support options available from Microsoft, please see
the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp For more information about using the sample code in this article, please
see the following article in the Microsoft Knowledge Base:
Q212536
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\
- img
- .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 : kbdta KbVBA
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto kbinfo
|