Friday, July 24, 2015

Import images to PowerPoint Automatically

In our day to day office work it is a regular task to make management presentations and obviously to do this we need many many images to be placed in powerpoint file.

What if we can do this at click of button :-)

So I have made a program which will do this work for you automatically.

Here is some automatic macro program to help you uploading pictures automatically from your hard disk into a PowerPoint presentation.

Follow the simple steps to have this macro in your book1 and then assign some shortcut so as to insert pictures automatically to your PowerPoint presentation.

STEPS
1) Copy the source code given in this post in between two lines
2) Open a new blank PowerPoint presentation with any name you like
3) It will ask you to click to add new slide - do it
4) Goto the Tools menu --> Macro --> Record New Macro
5) It will show default macro name as "Macro 1", just select OK
6) Now select STOP macro record button
7) Now press Alt + F11 to goto the Visual Basic editor
8) Expand the left window upto Module1 level by double clicking it
9) You will see Sub Macro1()
10) Select all code there and paste the code below in that window
11) Close the Visual Basic editor
12) Now press Alt + F8 buttons together to get macro Run dialogue box
13) Select the macro "ImageUpload" and press Run
14) It will ask for filetype (Default is JPG), press OK
15) It will automatically insert all images in the folder in which this Powerpoint file is placed

DONE :-)

Make such master file which contains this macro with any name you like say "ImageUplod.PPT"

Copy this file to any folder that contains images to be uploaded to PPT file, then rename it as you like, then open and run the macro to import all images at a stretch.

I know it is bit difficult to do this for very basic level people so they can just leave me a comment with email ID and I will send compiled file to them over email.

Also I have made complete code which adds a button toolbar, so just press a button and import images type, this will be posted by me in next week.

Cheers !!



Copy the code below :

'===============================================================================
Sub ImageUpload()

Dim wb As Presentation
Set wb = ActivePresentation


Dim strTemp As String
Dim strPath As String
Dim strDir As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape

strFileSpec = InputBox(Prompt:="Enter type of image files to import", _
Title:="ENTER FILE TYPE", Default:="JPG")
strFileSpec = "*." & strFileSpec

strPath = wb.Path & "\"
strFileSpec = "*.jpg"
strDir = strPath & strFileSpec
strTemp = Dir(strDir)
Do While strTemp <> ""

Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0, _
Width:=100, _
Height:=100)

With oPic
.ScaleHeight 1, msoTrue
.ScaleWidth 1, msoTrue
End With

strTemp = Dir
Loop

For NumSlide = 1 To ActivePresentation.Slides.Count
ActivePresentation.Slides(NumSlide).Select
For Each Picture In ActiveWindow.Selection.SlideRange.Shapes
Picture.Select
Picture.LockAspectRatio = msoTrue
Picture.Height = 450 'Change this numbers to fit your needs
'Picture.Width = 500 'Change this numbers to fit your needs
Next
Next
End Sub

'===============================================================================

No comments:

Post a Comment