Export Excel worksheets to individual pdfs using VBA code -


i have script want run in ms access export worksheets in late bound selected workbook individual pdfs in specific location pdf file names being names of worksheets. below have far, having trouble figuring out export code is. have tried modifying excel vba code (excel vba export selected sheets pdf) export, kept returning compile errors @ every step.

dim xls  object dim wkb  object dim wks1 object dim wks2 object dim wks3 object set xls = createobject("excel.application") set wkb = xls.workbooks.open("\\exchsvr1\stone\mold_books\" & mold_id & "\" & mid(mid(strflpath, instrrev(strflpath, "/") + 1), instrrev(strflpath, "\") + 1)) set wks1 = wkb.worksheets(1)  'code export first worksheet "c:\test\" & wks1.name set wks2 = wkb.worksheets(2)  'code export second worksheet "c:\test\" & wks2.name set wks3 = wkb.worksheets(3)  'code export third worksheet "c:\test\" & wks3.name 

based on comment, 1 example of compile errors you're facing:

enter image description here

that happens because xltypepdf excel constant , unknown access unless set reference microsoft excel object library.

since want use late binding, don't want add reference vba project. in case there 2 things can do.

  1. declare constant in access code: const xltypepdf long = 0 can continue use constant's name elsewhere in code without triggering compile error.
  2. or use constant's value (0) instead of name in access code.

and have deal other excel constants, such xlqualitystandard in same way.


Comments