Getting the original Picture back out of a Visio shape

Started by Visisthebest, August 23, 2023, 05:31:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Most impressive!  I'd click the like button but would get carpal tunnel syndrome.

Must observe that the final result is neither simple, direct, nor intuitive.  For a user, they're totally dependent upon the code doing everything.  So, I would rate this as User unfriendly.

Off the top of my head, considering all of the embellishments, plus the need to retrieve/update/change photo, I would do something like:  on drop add to group.  Perhaps add User cell to contain image name.  The border would be another, built-in group subshapes that over lays the pic.  Either it, or the parent can contain connection points.  Note, on drop, the pic can be centered and sized according to present group settings.  Thus, replacing existing pic is merely delete (optional) and drop new pic.  DONE.   Example of possibility:
Visio 2019 Pro


Quote from: Nikolay on August 25, 2023, 11:43:45 AM
It is just lying, there is "ForeignData" shape sheet cell, of course. If it existed, that would be a practical solution.
But it's not entirely wrong. If you open the VSDX file, there is "ForeignData" cell in the XML (see below)
OFFTOPIC: This cell is available via user interface or ShapeSheet?
Data1, Data2, Data3 are also there...


@wapperdude, you are absolutely right, it's not a user code. But we are developers here, are we not?  :)
And it's always code that is doing everything, the only difference is who's code is that, and how it's wrapped...

Here is a user-friendly (web) version running the code above 8)
User should be able to dorp any .vsdx file with images there, and get back images, with page and shape ids, as a zip archive:



Visio 2021 Professional


@Vizisthebest:  LOL.  I removed my post apparently as you were drafting your reply.  Basically, I decided to recall it.
Visio 2019 Pro


@Nikolay:  I would encourage you to resubmit the web development again, under Users submitted Stuff or perhaps Market....

It needs its own identity.
Visio 2019 Pro


The ol' gray mare ain't dead, and chatGPT (???) also lied. There is a 4th known, existing method that I stumbled upon.  Here's the reference:  Selection.Export Method

Based upon this, I did simple test.  Imported a pic onto a page and selected it.  Then ran my code to export the pic as png onto my desktop.  The method allows me to name the output file.  In the example, I called it Luc1.  It would be easy enough to embellish this two line code to use the existing Visio directory or other, and to change the file type.  I haven't investigated further than seeing if this actually works.  It does.

Here's my test code:

Sub exportPic()
    Dim MyPic As Visio.Shape
    Set MyPic = ActiveWindow.Selection(1)
    MyPic.Export ("C:\Users\yourusername\OneDrive\Desktop\Luc1.png")
End Sub

Oooops...sort of.... As I look at Yacine's post,  this is basically a stripped down version of that, sans the size and resolution statements.  Well, I'll leave it, as it may be of some value. 
Visio 2019 Pro


Thank you Wapperdude, did some more testing with GPT-4 and I must say it is also pretty good at producing useless code. You have to double-check everything. Frequently there is some good stuff in there too, so there is value, but this forum is much better than GPT-4!
Visio 2021 Professional


Curiosity still gnawing at me, I came across this 2012 forum post, Al Edlund to the rescue! In addition to solving the issue, early on he makes interesting comment about Visio exporting: 
QuoteAs in most methods in Visio vba, the export method is actually looking for an 'object'.
.  Ok.  I found it interesting.
Visio 2019 Pro


Visio 2019 Pro