excel - Clear copy of current file from data -
there workflow fill in sheet , mail when you're done. method mail send current sheet attachment, should directly create new copy of sheet data removed from.
i can clear current sheet, that's wrong, need clear new sheet. have read running macros on other workbooks, fails run macro. what's best solution?
sub senddata_click() if msgbox("sure send?", vbyesno, "confirm") = vbyes ' save current sheet activeworkbook.save ' send current file mail_activesheet ' mark sheet sent worksheets("data").range("b6").value = true ' create new emptied version create_new_copy msgbox "your data sent" end if end sub sub create_new_copy() dim wb workbook dim newfilename string dim fileextstr string dim filepath string set wb = activeworkbook newfilename = "filenamehere " & format(dateadd("d", 1, now), "yyyy-mm-dd") fileextstr = "." & lcase(right(wb.name, len(wb.name) - instrrev(wb.name, ".", , 1))) filepath = activeworkbook.path & "\" & newfilename & fileextstr ' # problem, how clear new file?? ' clear_sheet_invoices ' save sheet new file wb.savecopyas filepath end sub sub clear_sheet_invoices() dim ws worksheet set ws = worksheets("mydatasheet") ' remove contents ws.range("b2:f999").clearcontents ' mark "sent" flag new sheet false worksheets("data").range("b6").value = false end sub
as might note, using activeworkbook.savecopyas
create copy, , have sub clear_sheet_invoices
can clear required data. how run sub on new file?
i have thought copy mydatasheet
new sheet, clear data sheet, save new file , copy sheet back. on opening file, check if copy of sheet present , remove sheet. yeah, damn ugly, there should better way right? ;)
you can change definition of clear_sheet_invoices()
in way requires parameter of workbook
type , clear worksheet "mydatasheet" in workbook.
then can invoke sub , pass newly created workbook parameter.
below code need change implement it:
sub clear_sheet_invoices(wb workbook) dim ws worksheet set ws = wb.worksheets("mydatasheet") ' remove contents ws.range("b2:f999").clearcontents ' mark "sent" flag new sheet false wb.worksheets("data").range("b6").value = false end sub
sub create_new_copy() dim wb workbook dim newwb workbook dim newfilename string dim fileextstr string dim filepath string set wb = activeworkbook newfilename = "filenamehere " & format(dateadd("d", 1, now), "yyyy-mm-dd") fileextstr = "." & lcase(right(wb.name, len(wb.name) - instrrev(wb.name, ".", , 1))) filepath = activeworkbook.path & "\" & newfilename & fileextstr ' save sheet new file wb.savecopyas filepath set newwb = excel.workbooks.open(filepath) ' # problem, how clear new file?? call clear_sheet_invoices(newwb) call newwb.close(true) end sub
method senddata_click
doesn't require changes.
Comments
Post a Comment