excel vba - Error 1004 when printing PDFs after upgrade to Office 2016 -
i have workbook of ~50 worksheets. code loops through every sheet, assigns title row, print area , pagebreaks on each sheet , after prints pdf specific folder. code worked fine until last week, when have updated office 2016 (from excel 2013).
i error in part of code repeated @ every sheet, after ~25 pdfs printed (at same sheet default, when suppress part of code prints sheet, error on next sheet). error message appears in line marked **.
sub updatepdfs_click() 'some code saves workbook server location 3 times (first copy of initial one, second later opened & changed, , third 1 running code (deleted @ end)) 'code opens second workbook (pdfbook) , make adjustments (copying sheets , deleting content) 'code follows: pdfbook.save pdfbook.close true set pdfbook = application.workbooks.open(def_path & dir_name & "\" & filename2) dim sht01 worksheet each sht01 in pdfbook.worksheets if sht01.name = "sheet1" sht01.activate ' rows count & hpagebreaks finalrow = cells(rows.count, "d").end(xldown).row ' number of rows print printareaandhpagebreaks finalrow ' subroutine repeated ' pdf print activesheet.range("a1:d" & finalrow).exportasfixedformat type:=xltypepdf, _ filename:=path_pdf & "so-" & activesheet.range("a2") & "-" & activesheet.range("b2") & "-sheet1", quality:=xlqualityminimal activewindow.view = xlnormalview elseif sht01.name = "sheet2" sht01.activate 'etc sheets want print else ' sht01.delete end if next sht01 pdfbook.close true ' close dummy msgbox "pdfs created sucessfully" application.displayalerts = false dim strfile string strfile = activeworkbook.fullname activeworkbook.saved = true application.activeworkbook.changefileaccess xlreadonly kill strfile application.activeworkbook.close true application.displayalerts = true application.screenupdating = true end sub sub printareaandhpagebreaks(finalrow long) ' define print area activesheet.pagesetup.printarea = "" activesheet.resetallpagebreaks activesheet .pagesetup.printtitlerows = activesheet.rows(7).address .pagesetup.printarea = "a1:d" & finalrow .vpagebreaks.add before:=columns("d") .pagesetup.zoom = false .pagesetup.fittopageswide = 1 .pagesetup.fittopagestall = false end dim numhpb long dim rng range activewindow.view = xlpagebreakpreview numhpb = activesheet.hpagebreaks.count j = 1 numhpb set rng = activesheet.range("a" & activesheet.hpagebreaks.item(j).location.row) if rng.value = "" = 1 200 **if rng.offset(-(i), 0).interior.colorindex = 4 then** activesheet.hpagebreaks.add before:=rows(activesheet.hpagebreaks.item(j).location.row - i) exit end if next end if next j end sub
i error 1004, excel restarts or freezes. result in specified folder same: ~25 pdfs printed (to loop error arises in second sub), around 10 pdf have size of 5kb, others missing.
does know how solve error or going on?
Comments
Post a Comment