PowerPoint VBA code fails on second run without restarting ppt -


i'm using powerpoint 2013 on surface run slideshow. during slideshow, there code tracks time every slide changes , records in separate excel file.

it works how on first time run through powerpoint. however, if don't close powerpoint , restart program, second time through not anything. code works until first instance of "activesheet" or "activecell". gets line of code, code stops running. doesn't stop slideshow, doesn't record data.

it seems somehow powerpoint loses link excel.

what cause fail on "activesheet" or "activecell"?

code timer

dim intslide integer dim oexcel excel.application  dim owb workbook dim ws worksheet dim strpart string dim strcond string dim introw integer  public declare ptrsafe sub getsystemtime lib "kernel32" (lpsystemtime systemtime) public declare ptrsafe sub sleep lib "kernel32" (byval dwmilliseconds long)  public type systemtime     year integer     month integer     dayofweek integer     day integer     hour integer     minute integer     second integer     milliseconds integer end type 

code runs every page change

sub onslideshowpagechange(byval ssw slideshowwindow)     dim stime systemtime     dim lngcount long     dim check     dim strfinal string      getsystemtime stime      intslide = 1     lngcount = 1     introw = 1     strfinal = ""      intslide = ssw.view.currentshowposition      if intslide = 1         set oexcel = new excel.application         set owb = oexcel.workbooks.open("c:\users\ayse eren\desktop\timesaver.xlsx")         oexcel.visible = false         oexcel.sheets(1).activate         oexcel.sheets(1).range("a1").activate         strcond = "hud"         if oexcel.sheets(1).range("a1").value = ""             oexcel.sheets(1).range("a1").value = "participant"             range("a2").activate         else             oexcel.sheets(1).range("a1").offset(0, 1).end(xldown).offset(1, 0).activate             'uses column b (automatically populated) determine start recording data         end if          introw = activecell.row - 1     end if      oexcel.activesheet.range("a" & (intslide + introw)).activate      activecell.offset(0, 1) = strcond     activecell.offset(0, 2) = intslide     activecell.offset(0, 3) = stime.year     activecell.offset(0, 4) = stime.month     activecell.offset(0, 5) = stime.day     activecell.offset(0, 6) = stime.hour     activecell.offset(0, 7) = stime.minute     activecell.offset(0, 8) = stime.second     activecell.offset(0, 9) = stime.milliseconds      strfinal = activepresentation.slides(intslide).shapes(1).textframe.textrange.text     activecell.offset(0, 12) = strfinal      if intslide = 47         owb.save         oexcel.visible = true         oexcel.quit     else         owb.save     end if  end sub 

this code runs if exit slide show before slide 47.

edit

sub onslideshowterminate(byval ssw slideshowwindow)     owb.save     owb.close     oexcel.visible = true end sub 


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -