excel - How do i save as pdf via VBA -


i have code, want to:

  1. save masterfile (current active workbook),
  2. amend workbook , delete sheets,
  3. then save separate copies of edited workbook excel sheet , pdf file.

the problem have here code saves pdf file original masterfile after have tried activate edited excel file. here? appreciate advice! code below:

activeworkbook.save   sheets("inventory").select cells.select selection.copy cells.select selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _     :=false, transpose:=false application.displayalerts = false  sheets("may").select cells.select selection.copy cells.select selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _     :=false, transpose:=false  range("a1").select sheets("macro").select activewindow.selectedsheets.delete application.displayalerts = false  sheets("oct").select activewindow.selectedsheets.delete application.displayalerts = false  sheets("inventory").select range("a1").select  sheets("inventory").cells.interior.colorindex = 0  chdir "g:\9fixed\posi\2016\inventory" activeworkbook.saveas filename:= _     "g:\9fixed\posi\2016\inventory\asia fixed - " & format(date, "dd mmm") & ".xls", fileformat:= _     xlopenxmlworkbook, createbackup:=false application.displayalerts = false 'activeworkbook.exclusiveaccess application.displayalerts = true  workbooks("asia  - " & format(date, "dd mmm") & ".xls").activate activeworkbook.exportasfixedformat type:=xltypepdf, filename:= _ "g:\9fixed income\positions\2016\inventory\asia fixed income - " & format(date, "dd mmm") & ".pdf", quality:=xlqualitystandard, _ includedocproperties:=true, ignoreprintareas:=false, _ openafterpublish:=false 

i not reproduce issue having.

here 'test' code, using workbook 4 sheets , information in cells(1,1), 1 sheet named "may" --- deleted, , new file not have "may" , pdf not either.

i moved saveas code towards top of file. maybe fix issue, don't believe will.

option explicit sub savecopies()     dim c_outputdir string     dim sfilename string     dim fso object ' used handle paths, filenames, etc.     set fso = createobject("scripting.filesystemobject")     c_outputdir = "c:\temp\"     ' save master copy.     activeworkbook.save       ' generate new name file.     sfilename = fso.getbasename(activeworkbook.fullname) & "_" & format(date, "dd mmm")     ' save new working file.     activeworkbook.saveas filename:= _         c_outputdir & sfilename & ".xls", fileformat:= _         xlopenxmlworkbook, createbackup:=false      ' make changes working file.     application.displayalerts = false     activeworkbook.sheets("may").delete     application.displayalerts = true     ' save changes.     activeworkbook.save      ' save pdf of file.     activeworkbook.exportasfixedformat type:=xltypepdf, filename:= _     c_outputdir & sfilename & ".pdf", quality:=xlqualitystandard, _     includedocproperties:=true, ignoreprintareas:=false, _     openafterpublish:=false  end sub 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -