vba - PowerPoint 2013 macro keeps file locked open after close command -
i have powerpoint vba function opens presentations, copies slides active presentation, closes source presentation. worked fine in 2010, fails in 2013 (all on windows 7) if tries open same presentation more once. appears me after presentation.close command issued, window closed, file remains locked open until vba code exits. if code attempts open file again returns error: "method 'open' of object 'presentations' failed"
here's simplified form of function i'm running behaves same way. i've had colleague test again in powerpoint 2010 , runs fine. i've had colleague test under 2013 make sure it's not particular installation.
sub testopen() dim ppfile presentation dim integer const fpath = "c:\test.pptx" = 1 2 set ppfile = application.presentations.open(fpath) ppfile.close set ppfile = nothing next end sub
the file test.pptx blank presentation. in debug mode can see file opens , closes on first loop, on second loop open command fails , can see in windows explorer hidden temporary file still exists, indicating file still open, until exit vba code. verified file held open adding in function check file open status.
i've spent hour googling , cannot find other descriptions of problem. i'm sure can implement workaround it's driving me crazy can't find other reports of seemingly such simple issue. suggestions appreciated! thanks.
the best way have achieved create vbs file , in vbs file call out desired vba code. it's little more hassle write vba code, it's solution worked me.
for example in vbs file:
dim args, objpp set args = wscript.arguments set objpp = createobject("powerpoint.application") objpp.open "c:\path\to\file.ppx" objpp.visible = true objpp.run "the_macro" objpp.save objpp.close(0) objpp.quit
or better yet, have entire code within vbs file , have copy desired slides.
hope helps achieve result.
Comments
Post a Comment