Insert Image as a shape in Visio - VBA -
i want able import image shape in visio using vba. i've tried insert image using following, doesn't work... myshape.import(imagepath)
however, mypage.import(imagepath)
works fine , places image in center of page, have no way of manipulating shape. i've tried searching web, can't seem find way using vba.
just expanding on @tim , @mike comments here's quick snippet wraps import part function
sub tryaddimage() dim vpag visio.page set vpag = activepage dim shpimg visio.shape set shpimg = addimageshape(vpag, "c:\myimage.jpg") if not shpimg nothing 'do new shape shpimg.cellsu("width").formulau = "=height*0.5" end if end sub private function addimageshape(byref vpag visio.page, filename string) visio.shape dim shpnew visio.shape if not vpag nothing dim undoscopeid1 long undoscopeid1 = application.beginundoscope("insert image shape") on error resume next: set shpnew = vpag.import(filename) if not shpnew nothing application.endundoscope undoscopeid1, true else application.endundoscope undoscopeid1, false end if end if set addimageshape = shpnew end function
basically, function tries return shape import method. if method creates error, either non-existent path or appropriate image filter not being installed, function returns 'nothing', , can test in calling code.
Comments
Post a Comment