vba - Loop through dependent list selections and print out -
i have data validation drop down list 77 different selections need monthly report. vba newbie found code prints out selected option in folder, selection cell a1 (aka"strategy"). add loop through code automatically prints different selections seperate pdfs same folder. current code is:
sub pdfactivesheet() dim ws worksheet dim myfile variant dim strfile string dim sfolder string on error goto errhandler set ws = activesheet 'enter name , select folder file ' start in current workbook folder strfile = ws.range("a1").value & " strategy output " & ws.range("j1").value sfolder = getfolder() if sfolder = "" msgbox "no folder selected. code terminate." exit sub end if myfile = sfolder & "\" & strfile ws.exportasfixedformat _ type:=xltypepdf, _ filename:=myfile, _ quality:=xlqualitystandard, _ includedocproperties:=true, _ ignoreprintareas:=false, _ openafterpublish:=false, _ from:=1, _ to:=2 exithandler: exit sub errhandler: msgbox "could not create pdf file" resume exithandler end sub function getfolder() string dim dlg filedialog set dlg = application.filedialog(msofiledialogfolderpicker) dlg.initialfilename = thisworkbook.path & "\" dlg.title = "select folder save pdfs" if dlg.show = -1 getfolder = dlg.selecteditems(1) end if end function
the code have found on previous pages of site loop through of list follows, keep getting run time 1004 error on (application defined). know why?
private sub loop_through_list() dim cell excel.range dim rgdv excel.range dim dv_cell excel.range set dv_cell = range("strategy") set rgdv = application.range(mid$(dv_cell.validation.formula1, 2)) each cell in rgdv.cells dv_cell.value = cell.value call pdfactivesheet next end sub
Comments
Post a Comment