PPT97: Sample Code to Batch Import Serially Named Graphics FilesID: Q236626
|
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.
To use this macro, the following conditions must be true:
http://www.microsoft.com/support/supportnet/overview/overview.aspFor 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: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
Last Reviewed: July 13, 1999