excel - How to add pictures to Powerpoint Presentation Picture PlaceHolder? -
i have created code in excel vba create powerpoint presentation 1 slide each row of excel, , populate in specific text box in powerpoint.
want add in images match description. these jpegs , not charts etc.
how can this, , better in excel, or better powerpoint vba itself?
eitherway, able me out code on how please?
image frames exist in powerpoint. there 2 images per slide (no transitions or anything).
thank you!
p.s using powerpoint , excel 2010 on windows 7.
is there way excel? rest of code in excel , great part of macro.
have file location want use e.g. c:\insertfoldername\imagename.jpeg appears in column h in spreadsheet (about 400 rows).
powepoint template using has image frame (the 1 in powerpoint, wehn hover on says.."insert picture file".
these sized , in right location.
want is, in excel, paste image file path in excel , past specific image frame.
going possible @ all?
basically this:
ppt.activepresentation.slides(2).shapes(3)loadimage(spath)
below code using.
**** indicates file path. jpg file set 3rd column in excel spreadsheet.
sub createslides() 'dim excel objects dim objworkbook new excel.workbook dim objworksheet excel.worksheet 'dim file path string dim strfilepath string 'dim powerpoint objects dim ppt object dim pptslide powerpoint.slide dim pptlayout powerpoint.customlayout dim pptnewslide powerpoint.slide dim str string dim title string set ppt = getobject(, "powerpoint.application") ppt.visible = true 'get layout of first slide , set customlayout object set pptlayout = ppt.activepresentation.slides(1).customlayout 'run openfile function open file dialog box. returns string containing file , path. strfilepath = openfile() 'open excel file set objworkbook = excel.application.workbooks.open(strfilepath) 'grab first worksheet in workbook set objworksheet = objworkbook.worksheets(1) 'loop through each used row in column = 2 objworksheet.range("a65536").end(xlup).row set ppt = getobject(, "powerpoint.application") set pptnewslide = ppt.activepresentation.slides.addslide(ppt.activepresentation.slides.count + 1, pptlayout) 'get number of columns in use on current row dim lastcol long dim boldwords string boldwords = "line1: ,line2: ,line3: ,line4: " lastcol = objworksheet.rows(i).end(xltoright).column if lastcol = 16384 lastcol = 1 'for reason if column 1 has data returns 16384, correct 'build string of columns on row str = "" str = "line1: " & str & objworksheet.cells(i, 1).value & chr(13) & _ "line2: " & objworksheet.cells(i, 2).value & chr(13) & _ "line3: " & objworksheet.cells(i, 10).value & chr(13) & _ "line4: " & objworksheet.cells(i, 7).value & chr(13) & chr(13) & _ objworksheet.cells(i, 14).value sfile = cells(i, 3) & ".jpg" **** jpg name set ppt = getobject(, "powerpoint.application") spath = "c:\test\" 'write string slide pptnewslide.shapes(2).textframe.textrange.text = objworksheet.cells(i, 3).value 'this enters film title ppt.activepresentation.slides(ppt.activepresentation.slides.count).shapes(1).textframe.textrange.text = str boldsomewords ppt.activepresentation.slides(ppt.activepresentation.slides.count).shapes(1), str, boldwords 'this want load in image. 'ppt.activepresentation.slides(ppt.activepresentation.slides.count).shapes(3).picture = loadpicture(spath) ' & sfile) 'ppt.activepresentation.slides(2).shapes(3)loadimage((spath)) next end sub function openfile() 'dim file dialog object , string dim objfiledialog filedialog dim strfile string 'set objfiledialog instance of filedialog object set objfiledialog = application.filedialog(msofiledialogfilepicker) 'set properties of objfiledialog object objfiledialog.allowmultiselect = false objfiledialog.buttonname = "select" objfiledialog.initialview = msofiledialogviewdetails objfiledialog.title = "select excel file" objfiledialog.initialfilename = "c:\" objfiledialog.filters.clear objfiledialog.filters.add "excel", "*.xls; *.xlsx", 1 objfiledialog.filterindex = 1 'show filedialog box objfiledialog.show 'set strfile first record of selecteditems property of our filedialog strfile = objfiledialog.selecteditems(1) 'return file path string openfile = strfile end function
this how add pictures in open ppt picture placeholders using excel.
used early binding adding microsoft powerpoint 14.0 object library reference.
edit1: adding doevents , explanation
sub importpictureinplaceholderfromexcel() dim oppt powerpoint.application dim opptslide powerpoint.slide dim opptshp powerpoint.shape '~~> hold of ppt instance meaning open ppt presentation set oppt = getobject(, "powerpoint.application") '~~> reference first slide should contain picture placeholders set opptslide = oppt.activepresentation.slides(1) '~~> check each shape in slide each opptshp in opptslide.shapes '~~> need work on picture place holders if opptshp.placeholderformat.type = ppplaceholderpicture opptshp '~~> add picture '~~> example, picture path in cell a1 opptslide.shapes.addpicture range("a1").value, msofalse, msotrue, _ .left, .top, .width, .height '~~> insert doevents here specially big files, or network files '~~> doevents halts macro momentarily until '~~> system finishes it's doing loading picture file doevents end end if next set opptslide = nothing set oppt = nothing end sub to sum-up:
1. hold of ppt application
2. hold of slide , shapes within slide
3. choose shapes ppplaceholderpicture type only
4. use shape object's(ppplaceholderpicture type) .top, .left, .width , .height property argument shapes collection's .addpicture method.
and there go, you've added picture in ppt picture placeholder.
hope need.
Comments
Post a Comment