excel - Avoiding Activate by saving files when using many workbooks -


i have special cases, cannot find way around activate considered bad (slow) coding in vba. in case looping on sheets of original workbook, copy contents sheets - under conditions - paste these contents new workbook , try save result csv-files. doing using following save-routine:

private sub saveworksheet(pathx, wbkn, sheetn)  path = pathx & ".csv" workbooks(wbkn).sheets(sheetn).activate  workbooks(wbkn).saveas filename:=path, _ fileformat:=xlcsv, local:=true, createbackup:=false  end sub 

if don't use activate error. there way avoid when saving files?

edit: info on why activate considered bad: how avoid using select in excel vba macros excel select vs activate

edit2: after research , testing, found out problem not save method itself, rather context of multiple workbooks being involved. not think can prevent activate when saving file another workbook or when running macro on another workbook, while doing stuff on 'original' base-workbook. can prevent use when working on same (ie 'original') workbook time. please correct me if wrong.

when want save sheet csv, why dont use worksheet in question directly. workbook save csv requires know active sheet

private sub saveworksheet(pathx, wbkn, sheetn)     dim ws worksheet     path = pathx & ".csv"     set ws = worksheets(sheetn)     ws.saveas filename:=path, fileformat:=xlcsv, local:=true, createbackup:=false end sub 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -