i've got working i'm stuck on 1 part. here's i'm trying do:
- save outlook email attachment (.csv file)
- open attachment in excel
- delete last 6 lines of file
- re-save file
i'm able save file , open in excel, nothing else happens. no matter try i'm unable actions happen within excel; can't delete last 6 rows (parse footer). appreciated!
public sub saveattachtodisk(itm outlook.mailitem) dim objatt outlook.attachment dim savefolder string dim attachname string dim oxl object, owb object, osheet object savefolder = "c:\temp\" each objatt in itm.attachments objatt.saveasfile savefolder & "\" & objatt.displayname attachname = objatt.displayname set objatt = nothing next ' start excel , application object set oxl = createobject("excel.application") ' hide excel oxl.visible = false ' open file set owb = oxl.workbooks.open(savefolder & attachname) 'set worksheet set osheet = owb.sheets("sheet1") 'parse footer activecell.specialcells(xllastcell).select activecell.offset(-5, 0).range("a1:a6").select activecell.activate selection.clearcontents 'save file set owb = oxl.workbooks.save(savefolder & "\" & objatt.displayname) 'clean owb.close (true) oxl.quit set owb = nothing set oxl = nothing end sub
this line
set owb = oxl.workbooks.save(savefolder & "\" & objatt.displayname)
needs refer attachname
string stored earlier
set owb = oxl.workbooks.save(savefolder & "\" & attachname)
because objatt nothing
@ point.
use
msgbox objatt.displayname
just before save can check suitable.
btw comment out line hides excel (visible = true) , step through code pressing f8 can see happening.
Comments
Post a Comment