excel vba - Errors in assigning dimensions of a shape -


i want create macro recognizes size , location of existing shape "picture 1" (an enhanced metafile) in , deletes shape, copies chart "chart 3" workbook original workbook enhanced metafile, , sizes / moves copy identical size / location of original shape.

i have declared destination worksheet "wkst" , source worksheet "source". works except 1 thing: first dimension of copied shape off original shape, regardless of dimension set first. in case of code below, shape's height changes slightly.

i added message boxes make sure matched in value msgbox currenth (the height of original shape) not display same value msgbox wkst.shapes("picture 1").height (the height of copied shape); changes i.e. 594 572

any great, thanks!

dim currentw double dim currenth double dim currentt double dim currentl double      currenth = wkst.shapes("picture 1").height     currentw = wkst.shapes("picture 1").width     currentt = wkst.shapes("picture 1").top     currentl = wkst.shapes("picture 1").left      msgbox currenth     msgbox currentw     msgbox currentt     msgbox currentl      source.chartobjects("chart 3").copy     wkst.shapes("picture 1").delete     wkst.activate     wkst.pastespecial format:="picture (enhanced metafile)", link:=false, displayasicon:=false     activewindow.selection             .name = "picture 1"             .height = currenth             .width = currentw             .left = currentl             .top = currentt     end      msgbox wkst.shapes("picture 1").height     msgbox wkst.shapes("picture 1").width     msgbox wkst.shapes("picture 1").top     msgbox wkst.shapes("picture 1").left  

in situation need add more parameters set dimensions of shape copied. therefore instead of part of code:

with activewindow.selection         .name = "picture 1"         .height = currenth         .width = currentw         .left = currentl         .top = currentt end 

you need add one:

with wkst.shapes(wkst.shapes.count) '<-- code set parameters of shape therefore _                                     line need changed,         .name = "picture 1"         .left = currentl         .top = currentt 'new part -->         .lockaspectratio = msofalse     dim ratio double         ratio = currenth / currentw         .scaleheight ratio, msofalse, msoscalefromtopleft '<--new part         .width = currentw         .height = currenth end 

the order of parameters important. code tried , tested , it's working fine me.


Comments