excel - Creating folders and new *.xlsx file with macro from template like xlsm file -


i have code creates folder , saves actual file in it, want saves copy 1 sheet in it. file code works template...

you write stuff , press button , saves .xlsx file 1 sheet (the sheet form) in new created folder... hundreds of files folders.

so in end should work this:

  1. you open .xlsm file code below in.
  2. you got sheets 1 form (what should "exported" later on) , list copy stuff in form.
  3. when filled form , press button , saves form sheet in new folder .xlsx , can continue in .xlsm file.

if it's unclear please ask.

the code have now

sub macro1() dim strfilename, strdirname, strpathname, strdefpath string on error resume next ' if directory exist goto next line strdirname = range("d81").value ' new directory name  strfilename = range("d8").value 'new file name strdefpath = application.activeworkbook.path 'default path name if isempty(strdirname) exit sub if isempty(strfilename) exit sub  mkdir strdefpath & "\" & strdirname strpathname = strdefpath & "\" & strdirname & "\" & strfilename 'create total string  activeworkbook.saveas filename:=strpathname & ".xlsm", _ fileformat:=xlopenxmlworkbookmacroenabled, password:="", writerespassword:="", _ readonlyrecommended:=false, createbackup:=false end sub 

problem here have names forms 1102,1103 going on that. next step there files name 1102_1 , 1102_2 , both should go in folder 1102 ...

it's bit out of knownledge please me guys :) greets

now using code below problem closes xlsm file annoyes , when reopen it wants update file need remove don't know how :/... , should export/save 1 special sheet

private sub commandbutton1_click() dim strfilename string, _ strdirname string, _ strpathname string, _ strdefpath string, _ sheettoexport string, _ wbmaster workbook, _ wbcopy workbook   on error resume next ' if directory exist goto next line strdirname = range("w12").value ' new directory name strfilename = range("d8").value 'new file name  set wbmaster = application.activeworkbook sheettoexport = range("a1").value 'or specify userform output  strdefpath = wbmaster.path 'default path name  if isempty(strdirname) exit sub if isempty(strfilename) exit sub  mkdir strdefpath & "\" & strdirname strpathname = strdefpath & "\" & strdirname & "\" & strfilename 'create total string  wbmaster.sheets(sheettoexport).copy set wbcopy = application.activeworkbook  wbcopy.saveas filename:=strpathname & ".xlsx", _                 fileformat:=xlopenxmlworkbook, password:="", writerespassword:="", _                 readonlyrecommended:=false, createbackup:=false  wbcopy.close end sub 

be careful on variable declaration!

the way did in op (original post) :

strfilename, strdirname , strpathname declared variant , not string.

you can still use them it'll take more memory , can issue if use them arguments.


see code :

dim strfilename string, _     strdirname string, _     strpathname string, _     strdefpath string, _     sheettoexport string, _     wbmaster workbook, _     wbcopy workbook   on error resume next ' if directory exist goto next line strdirname = range("d81").value ' new directory name strfilename = range("d8").value 'new file name  set wbmaster = application.activeworkbook sheettoexport = range("a1").value 'or specify userform output  strdefpath = wbmaster.path 'default path name  if isempty(strdirname) exit sub if isempty(strfilename) exit sub  mkdir strdefpath & "\" & strdirname strpathname = strdefpath & "\" & strdirname & "\" & strfilename 'create total string  wbmaster.sheets(sheettoexport).copy set wbcopy = application.activeworkbook  wbcopy.saveas filename:=strpathname & ".xlsx", _                 fileformat:=xlopenxmlworkbook, password:="", writerespassword:="", _                 readonlyrecommended:=false, createbackup:=false  closingwb = msgbox("do wish close exported file?",vbyesno,"close exported file") if closingwb <> vbno wbcopy.close 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -