vba - Paste Excel worksheet to a PowerPoint presentation -


i'm attempting paste excel finished powerpoint presentation. i've taken bits of code peltier tech , spreadsheet guru. macro intended work within excel template produces excel worksheet paste powerpoint.

i've tested code in output worksheet , works.

output when macro works

however, when macro executed real in excel template fails.

output when macro fails

do need define output worksheet object variable? , how reference variable in excel powerpoint paste loop , myrangearray section?

please note, objppt defined in macro upstream of grandfinale().

sub grandfinale()  dim pppres powerpoint.presentation  dim ppslide powerpoint.slide dim shp object dim myslidearray variant dim myrangearray variant dim x long  set objppt = getobject(, "powerpoint.application") set pppres = objppt.activepresentation set ppslide = pppres.slides(objppt.activewindow.selection.sliderange.slideindex)  'declare pp slides myslidearray = array(13, 14, 15, 16, 17, 18, 19, 20, 21, 22)  'declare excel ranges myrangearray = array(sheet2.range("a6:c18"), sheet2.range("a21:c33"), _     sheet2.range("a36:c48"), sheet2.range("a51:c63"), sheet2.range("a66:c78"), _    sheet2.range("a81:c93"), sheet2.range("a96:c108"), sheet2.range("a111:c123"), sheet2.range("a126:c138"), sheet2.range("a141:c153"))  'excel powerpoint paste loop x = lbound(myslidearray) ubound(myslidearray) myrangearray(x).copy set shp = pppres.slides(myslidearray(x)).shapes.pastespecial(datatype:=2) 'adjust images pppres.pagesetup     shp.left = (.slidewidth \ 2) - (shp.width \ 2)     shp.top = (.slideheight \ 2) - (shp.height \ 2) end  next x application.cutcopymode = false end sub 

the original question lacks details original worksheet or does, if in workbook, , macro ran other workbook must first create new workbook with

dim wb workbook wb = application.workbooks.add 

if workbook existing workbook use open instead

set wb =  workbooks.open("templatewb.xls") 

to specific sheet need, if created new workbook scrap use first sheet:

dim ws worksheet ws =wb.worksheets(1) 

or create 1 scrap

dim ws worksheet set ws = wb.worksheets.add 

the ws variable sent macro

grandfinale ws 

you need modify sub take worksheet argument

sub grandfinale(tempsheet worksheet) 

in code change occurrences of sheet2 tempsheet or variable name use.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -