excel - exporting a certain worksheet from a workbook to pdf -


i amateur programmer learning how program using vba

without further due, question :

i have created listbox (listbox1) i've listed sheets(ws) name in specific workbook. i've created listbox(listbox2) when select sheets name on listbox1, transfer listbox2.

my main objective choosing 1 or more sheets listed in listbox2, , clicking button, i'll manage save selected sheets in 1 pdf file.

here code button used export file in pdf i've written i've managed export them not in 1 pdf file in numerous amount of pdf file.

dim nomtableau() string  each wkbkname in application.workbooks()     if wkbkname.name = choix_poteau.value & "_" & section & "_" & projet & ".xlsx" wkbkname.activate goto lois end if     next  set wbk = workbooks.open(add1 & "\" & me.projet.value & "\" & me.section.value & "\poteaux\" & me.choix_poteau.value & "_" & me.section & "_" & me.projet & ".xlsx")  lois:  = 0 listbox2.listcount - 1 while listbox2.list(i) <> "" dim ws worksheet  each ws in worksheets  if ws.name = listbox2.list(i)  activesheet.exportasfixedformat type:=xltypepdf, filename:= _ "c:\export\resultats__" & listbox2.list(i - counter) & ".pdf", quality:=xlqualitystandard, _ includedocproperties:=true, ignoreprintareas:=false, openafterpublish:= _ true  end if  next wend  next end sub 

thanks alot, appreciate help

instead of exporting each sheet individually, select them first , call exportasfixedformat method.

here test code, worked expected:

option explicit  private sub testpdf()          dim integer         dim arrsheets() string         dim strsheets string          'get our sheet names         = 1 3                 strsheets = worksheets(i).name & "," & strsheets         next          'trim trailing comma         strsheets = left(strsheets, len(strsheets) - 1)          arrsheets = split(strsheets, ",")          thisworkbook.sheets(arrsheets).select          activesheet.exportasfixedformat type:=xltypepdf, filename:= _         "c:\users\qzbcjs\documents\useful workbooks\test.pdf", quality:=xlqualitystandard, _         includedocproperties:=true, ignoreprintareas:=false, openafterpublish:= _         true  end sub 

i declared array of strings, populated string variable comma-delimited names of worksheets (in case wanted first through third sheets), split comma-delimited string array , used array select of desired sheets , called exportasfixedformat method once.

adapting method code, beginning lois part this:

lois:          dim ws worksheet         dim arrsheets() string         dim strws string          = 0 listbox2.listcount - 1                 while listbox2.list(i) <> ""                          each ws in worksheets                                 if ws.name = listbox2.list(i)                                         strws = ws.name & "," & strws                                 end if                         next                 wend         next          strws = left(strws, len(strws) - 1)          arrsheets = split(strws, ",")          thisworkbook.sheets(arrsheets).select          activesheet.exportasfixedformat type:=xltypepdf, filename:= _         "c:\export\resultats__" & listbox2.list(i - counter) & ".pdf", quality:=xlqualitystandard, _         includedocproperties:=true, ignoreprintareas:=false, openafterpublish:= _         true 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -