Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2022, 03:51 AM
JanH JanH is offline Insert a Picture by ShapeData Windows 10 Insert a Picture by ShapeData Office 2019
Novice
Insert a Picture by ShapeData
 
Join Date: Apr 2022
Posts: 3
JanH is on a distinguished road
Question Insert a Picture by ShapeData

Hello,



is it possible to insert a picture in the shape by ShapeData informations?


scenario:

1) Shape have the ShapeData: "Number"
2) Value of "Number" is "12345"
3) Visio look up "12345" in the folder C:\Users\Pictures
4) Visio inserts Picture with the Name "12345" in the middle of the shape
Reply With Quote
  #2  
Old 04-13-2022, 06:02 PM
Guessed's Avatar
Guessed Guessed is offline Insert a Picture by ShapeData Windows 10 Insert a Picture by ShapeData Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Via a VBA macro - Yes.

Is this supposed to run on a particular shape or across all the shapes on the page/document?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 04-13-2022, 11:05 PM
JanH JanH is offline Insert a Picture by ShapeData Windows 10 Insert a Picture by ShapeData Office 2019
Novice
Insert a Picture by ShapeData
 
Join Date: Apr 2022
Posts: 3
JanH is on a distinguished road
Question

Quote:
Originally Posted by Guessed View Post
Via a VBA macro - Yes.

Is this supposed to run on a particular shape or across all the shapes on the page/document?

Hi,

thank you for the quick response.

It is supposed to run on all shapes across the page.
There are 150+ identical shapes with different "Number" values on the page.


Could you please make an example for the VBA macro?
Reply With Quote
  #4  
Old 04-14-2022, 07:17 PM
Guessed's Avatar
Guessed Guessed is offline Insert a Picture by ShapeData Windows 10 Insert a Picture by ShapeData Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This code works as a starting point. There are subtle points that you may need to use to refine the location of the graphic. PinX and PinY is dependent on the LocPinX and LocPinY which may not be the middle of both the shp or the shpNew. Then you a question about sizing/relative sizing of the graphic.
Code:
Sub ProcessPage()
  Dim shp As Shape, pg As Page, sPath As String, sFile As String
  Dim dSpcX As Double, dSpcY As Double, shpNew As Shape
    
  sPath = ActiveDocument.Path
  For Each pg In ActiveDocument.Pages
    For Each shp In pg.Shapes
      If shp.CellExists("Prop.Number", 0) Then
        dSpcX = shp.Cells("PinX")
        dSpcY = shp.Cells("PinY")
        sFile = Replace(shp.Cells("Prop.Number").Formula, """", "")
        Debug.Print sPath, sFile
        Set shpNew = pg.Import(sPath & sFile & ".png")
        With shpNew
          .Cells("PinX") = dSpcX
          .Cells("PinY") = dSpcY
        End With
      End If
    Next shp
  Next pg
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 04-20-2022, 02:33 AM
JanH JanH is offline Insert a Picture by ShapeData Windows 10 Insert a Picture by ShapeData Office 2019
Novice
Insert a Picture by ShapeData
 
Join Date: Apr 2022
Posts: 3
JanH is on a distinguished road
Thumbs up

Quote:
Originally Posted by Guessed View Post
This code works as a starting point. There are subtle points that you may need to use to refine the location of the graphic. PinX and PinY is dependent on the LocPinX and LocPinY which may not be the middle of both the shp or the shpNew. Then you a question about sizing/relative sizing of the graphic.
Code:
Sub ProcessPage()
  Dim shp As Shape, pg As Page, sPath As String, sFile As String
  Dim dSpcX As Double, dSpcY As Double, shpNew As Shape
    
  sPath = ActiveDocument.Path
  For Each pg In ActiveDocument.Pages
    For Each shp In pg.Shapes
      If shp.CellExists("Prop.Number", 0) Then
        dSpcX = shp.Cells("PinX")
        dSpcY = shp.Cells("PinY")
        sFile = Replace(shp.Cells("Prop.Number").Formula, """", "")
        Debug.Print sPath, sFile
        Set shpNew = pg.Import(sPath & sFile & ".png")
        With shpNew
          .Cells("PinX") = dSpcX
          .Cells("PinY") = dSpcY
        End With
      End If
    Next shp
  Next pg
End Sub

Thank you!
I will try it
Reply With Quote
Reply

Tags
picture, shapedata

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert a Picture by ShapeData Using IncludePicture and MailMerge to insert picture that is taken from a a picture lookup in Excel nic-nax Mail Merge 4 05-14-2019 10:34 PM
Insert a Picture by ShapeData Picture content control -> insert picture -> empty? Jaymond Flurrie Word 3 07-13-2016 07:00 AM
Insert a Picture by ShapeData How do I insert pictures directly into picture boxes by clicking the box instead of using INSERT>PIC Bree Word 1 06-24-2016 10:32 PM
Insert a Picture by ShapeData "Insert Picture\Link to File..." embeds picture sinz54 Drawing and Graphics 1 09-29-2013 06:31 PM
Insert a Picture by ShapeData Can I insert a picture into a picture ? alexcalgary Drawing and Graphics 2 10-16-2010 03:29 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft