excel - Auto save & close workbooks, except VBAWorkbooks -
currently trying figure out how have code auto saves , closes open workbooks avoid vba project workbooks without naming vba project workbooks. there way code recognize vba workbooks vs other open workbooks i'm trying save , close?
option explicit public thisfile string public path string sub closeandsaveopenworkbooks() dim wkb workbook path = [d1] application .screenupdating = false 'loop through workbooks collection each wkb in workbooks wkb 'if not on macro workbook if .name <> thisworkbook.name 'if book read-only 'don't save close if not wkb.readonly 'save current workbook current workbooks cell a1 file name .saveas filename:=(path & "\" & wkb.sheets(1).range("a1").value & ".xls"), fileformat:=xlexcel8 end if 'closing here leaves app running, no books .close end if end next wkb .screenupdating = true end end sub
a follow question thread: vba: auto save&close out of current workbooks except macro workbook
got answer!
reading through article provided j_v helped. replaced
if .name <> thisworkbook.name
with
if wkb.hasvbproject = false
hope ends helping others. 1 time again j_v!
excel vba excel-vba
No comments:
Post a Comment