Word Macro Behaves Badly Inside Content Control (Paste & Resize image)
i cobbled pretty cool macro internet, , works great regular word document.
the use case has powerpoint slide bunch of stuff on (picture, boxes, text, arrows, etc.) ctrl-a, ctrl-c powerpoint, , before macro, ctrl-v (as jpg) into word , always have resize it.
this macro resizes pastes it. can't figure out why same macro doesn't work if i'm in content control? don't error, "works" in sense powerpoint content saved jpg word, won't resize it. it's code runs, somehow pasted image inside content control read-only or properties read-only.
can explain behavior?
application.screenupdating = false selection.pastespecial link:=false, datatype:=15, placement:=wdinline, displayasicon:=false 'get image added (last image, li) li = activedocument.inlineshapes.count activedocument.inlineshapes(li).lockaspectratio = msotrue activedocument.inlineshapes(li).height = 0.64 * activedocument.inlineshapes(li).height application.screenupdating = true
to current content control, use document_contentcontrolonenter macro:
private sub document_contentcontrolonenter(byval contentcontrol contentcontrol)
msgbox activedocument.range(0, contentcontrol.range.end).contentcontrols.count
end sub
note there inconsistencies macro timing if you're using picture content control, though. if click on blue surround, not on icon, before inserting picture, runs then, if first click on icon, it runs after inserting picture.
re: "i didn't realize pastespecial returns reference shape", doesn't. what's being done there pastespecial output being assigned ishp variable.
cheers
paul edstein
[ms mvp - word]
Microsoft Office > Word IT Pro Discussions
Comments
Post a Comment