vba - Filename of individual split files in PowerPoint -
there
i have problem in ms powerpoint. working dozen files @ least 100 slides in each. need create individual slides individual files uploading purpose. got code split file individual slides. query how rename files automatically using vba code?
each slide has title in text box, , shape , size of title text box consistent across decks. how ensure individual files created saved "title of slide" file name?
as of now, file saved "original file name.n-n"
would appreciate in this.
following code found on internet split slide deck multiple individual files (one slide eaach, purpose):
sub splitfile() dim lslidesperfile long dim ltotalslides long dim osourcepres presentation dim otargetpres presentation dim sfolder string dim sext string dim sbasename string dim lcounter long dim lpresentationscount long ' how many split dim x long dim lwindowstart long dim lwindowend long dim ssplitpresname string on error goto errorhandler set osourcepres = activepresentation if not osourcepres.saved msgbox "please save presentation try again" exit sub end if lslidesperfile = clng(inputbox("how many slides per file?", "split presentation")) ltotalslides = osourcepres.slides.count sfolder = activepresentation.path & "\" sext = mid$(activepresentation.name, instr(activepresentation.name, ".") + 1) sbasename = mid$(activepresentation.name, 1, instr(activepresentation.name, ".") - 1) if (ltotalslides / lslidesperfile) - (ltotalslides \ lslidesperfile) > 0 lpresentationscount = ltotalslides \ lslidesperfile + 1 else lpresentationscount = ltotalslides \ lslidesperfile end if if not ltotalslides > lslidesperfile msgbox "there fewer " & cstr(lslidesperfile) & " slides in presentation." exit sub end if lcounter = 1 lpresentationscount ' slides leave in presentation? lwindowend = lslidesperfile * lcounter if lwindowend > osourcepres.slides.count ' odd number of leftover slides in last presentation lwindowend = osourcepres.slides.count lwindowstart = ((osourcepres.slides.count \ lslidesperfile) * lslidesperfile) + 1 else lwindowstart = lwindowend - lslidesperfile + 1 end if ' make copy of presentation , open ssplitpresname = sfolder & sbasename & _ "_" & cstr(lwindowstart) & "-" & cstr(lwindowend) & "." & sext osourcepres.savecopyas ssplitpresname, ppsaveasdefault set otargetpres = presentations.open(ssplitpresname, , , true) otargetpres x = .slides.count lwindowend + 1 step -1 .slides(x).delete next x = lwindowstart - 1 1 step -1 .slides(x).delete next .save .close end next ' lpresentationscount normalexit: exit sub errorhandler: msgbox "error encountered" resume normalexit end sub
this have pick text title , use output presentation name:
ssplitpresname = sfolder _ & osourcepres.slides(lwindowstart).shapes.title.textframe.textrange.text _ & "." & sext
if slide doesn't have title, you'll error, you'd need test , decide how name split presentation in case. maybe:
ssplitpresname = sfolder _ & "slide-" & cstr(lwindowstart) _ & "." & sext
you'd want run slide title through function removes characters not valid filenames in operating system(s) presentation viewed.
Comments
Post a Comment