When embedding an OLEObject (Word/XLS/PDF doc) in Excel, how can I set the icon's position relative to the attachment button? -
i'm trying create button allow me attach word/excel/pdf files. i've read bunch of other articles , tutorials, have button , vba macro gives me dialogue box browse file of choice. file can selected , embeds in excel fine.
issue i'm having getting position of embedded file sit next button i've created. @ moment defaults top left of active sheet, despite best efforts hard code different position in.
so 2 questions:
- how set position oleobject?
- is there way can identify cell reference/position of command button, , set position of oleobject relative it? example, 2 columns right of button.
thanks jk
here's code far:
sub attachfile() 'identify cell command button in , set location attachment icon 3 columns right dim buttonname string dim buttonaddress string dim buttonlocation range dim iconlocation range buttonname = activesheet.shapes(application.caller).name buttonaddress = activesheet.shapes(buttonname).topleftcell.address set iconlocation = range(buttonaddress).offset(0, 3) 'browse file dim vfile variant vfile = application.getopenfilename("all files,*.*", title:="find file insert") if lcase(vfile) = "false" exit sub 'embed selected file dim attachment oleobject set attachment = activesheet.oleobjects.add( _ filename:=vfile, _ link:=false, _ displayasicon:=true) 'reposition icon next command button activewindow.zoom = 100 attachment .top = iconlocation.top .left = iconlocation.left end activewindow.zoom = 70 end sub
i think have correct approach. try change code this
with attachment .top = cells("h89").top .left = cells("h89").left end
im not near vba, that
Comments
Post a Comment