Wednesday 15 May 2013

vba - Finding linked objects in Word -



vba - Finding linked objects in Word -

i want find objects in microsoft word 2010 file linked external files. example, if author has graph linked excel want find graph in document. can step through inlineshape collection in vba , examine properties have not found way tell me in document these shapes are. in other words, know, say, page number shape sits in. want inquire authors send me spreadsheets (typically) behind pictures , want convert of these shapes pictures. can wholesale convert them pictures in vba i’d rather 1 @ time can examine result. searching hand in big document tedious!

i wrote next code display info on linked pictures , re-create lastly linked image clipboard. there can paste scrap document know looking for, rough way job.

sub links_finder() ' find things linked elsewhere ' oct 20, 2014 dim oshape inlineshape, n integer, strmsg string strmsg = "found many linked things in document: " n = 0 on error resume next each oshape in activedocument.inlineshapes oshape.select if oshape.type = wdinlineshapechart n = n + 1 debug.print n debug.print oshape.linkformat.sourcefullname debug.print oshape.linkformat.sourcepath debug.print oshape.linkformat.type oshape.select selection.copy strmsg = strmsg & n & vbcrlf strmsg = strmsg & "copied lastly 1 found clipboard" strmsg = strmsg & vbcrlf & oshape.linkformat.sourcefullname strmsg = strmsg & vbcrlf & oshape.linkformat.sourcepath & vbcrlf & " link type: " & oshape.linkformat.type ' break link , insert picture, utilize this: 'selection.copy 'selection.pastespecial link:=false, datatype:=wdpasteenhancedmetafile, _ placement:=wdinline, displayasicon:=false end if next msgbox strmsg end sub

it turns out pretty close answering own question. l42 suggested, oshape.activate, in code, bring page shape in question. added code nowadays source in message box , inquire myself if want stop there or go on looking. message box appears in document above shape in question. revised code below.

sub links_finder() ' find things linked elsewhere ' oct 24, 2014 dim oshape inlineshape, n integer, strmsg string dim msg, style, title, response, mystring strmsg = "found many linked things in document: " n = 0 on error resume next each oshape in activedocument.inlineshapes oshape.select if oshape.type = wdinlineshapechart n = n + 1 debug.print n debug.print oshape.linkformat.sourcefullname debug.print oshape.linkformat.sourcepath debug.print oshape.linkformat.type oshape.select selection.copy strmsg = strmsg & n & vbcrlf strmsg = strmsg & "copied lastly 1 found clipboard" strmsg = strmsg & vbcrlf & oshape.linkformat.sourcefullname strmsg = strmsg & vbcrlf & oshape.linkformat.sourcepath & vbcrlf & " link type: " & oshape.linkformat.type msg = "source graphic: " & oshape.linkformat.sourcefullname & vbcrlf msg = msg & "do want go on looking?" ' define message. style = vbyesno ' define buttons. title = "looking linked tables" ' define title. response = msgbox(msg, style, title) if response = vbyes ' user chose yes. mystring = "yes" ' perform action. else ' user chose no. exit mystring = "no" ' perform action. end if ' break link , insert picture, utilize this: 'selection.copy 'selection.pastespecial link:=false, datatype:=wdpasteenhancedmetafile, _ placement:=wdinline, displayasicon:=false end if next msgbox strmsg end sub

vba ms-word word-vba

No comments:

Post a Comment