Fill a SmartArtLayouts with a existing picture

drom

Active Member
Joined
Mar 20, 2005
Messages
465
Office Version
  1. 2019
  2. 2016
  3. 2013
  4. 2011
  5. 2010
  6. 2007
Hi and thanks in advance!
I am having some probles when trying to fill a shape with a picture located in my folder
The Picture exist
Actually I have tried with many different pictures and extensions



VBA Code:
Sub FillShapeWithPicture()
  On Error Resume Next:                   Application.ScreenUpdating = False
Dim ogSALayout As SmartArtLayout:         Set ogSALayout = Application.SmartArtLayouts(1)    'I Do no care any if I have to put 5, 8, or...
  Dim ogShp As Object:                    Set ogShp = ActiveSheet.Shapes.AddSmartArt(ogSALayout)
Dim QNode As SmartArtNode
  Dim QNodes As SmartArtNodes:            Set QNodes = ogShp.SmartArt.AllNodes
Dim XX As Integer:                        XX = QNodes.Count
Dim X As Integer
  Dim wPictureFullName As String:         wPictureFullName = "C:\Users\WINDOWS 7\aaaaPendingJOBS\0000_FOTOS\AFRICA.jpeg"
    
    For X = XX To 2 Step -1
      QNodes(X).Delete
    Next X
  
  'With ActiveSheet.Shapes("Diagram 27").Fill                              'Using this Does not work either
  'With ogShp.Fill ' ActiveSheet.Shapes("Diagram 24").Fill           'Using this Does not work either
  ogShp.Select
 'UNTIL HERE WORKS FINE
'From Now on NO

  With Selection.ShapeRange.Fill
    .Visible = msoTrue
    .UserPicture wPictureFullName 'CStr(wPictureFullName)    ' Using any of this Does not work either
    .TextureTile = msoFalse
    .RotateWithObject = msoTrue
  End With

End Sub



When I use the Macro recorded, I can't get the code from there...
I do not see in VBA anything apart of, anything rather than:
VBA Code:
Sub b()
' b Macro
    ActiveSheet.Shapes.Range(Array("Diagram 30")).Select
End Sub
Although I get the image on my shape, Although the shape is filled with the selected picture from my folder


I have tried:
Insert Image to shape existing previous question
But for me does not work despite changing:
ActiveSheet.Shapes.Range(Array("Diagram XX")).Select




ps: I know I can insert a image easily using:
VBA Code:
Sub InsertPhoto()
  Dim wPictureFullName As String:         wPictureFullName = "C:\Users\WINDOWS 7\aaaaPendingJOBS\0000_FOTOS\AFRICA.jpeg"
                                                               ActiveSheet.Pictures.Insert(wPictureFullName).Select
Dim ShpPhotoNew As Object:                Set ShpPhotoNew = Selection
  'And change the location and...                                          
end sub

BUT i am trying to learn how to fill a SmartArtLayouts with a existing picture located in a string
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,756
You'll need to refer to the shape within the node. Therefore, try replacing...

VBA Code:
With Selection.ShapeRange.Fill

with

VBA Code:
With QNodes(1).Shapes(1).Fill

Note that you can delete this line...

VBA Code:
ogShp.Select

Hope this helps!
 
Solution

Forum statistics

Threads
1,144,278
Messages
5,723,463
Members
422,498
Latest member
KAT112014

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top