Fill a SmartArtLayouts with a existing picture

drom

Well-known Member
Joined
Mar 20, 2005
Messages
543
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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!
 
Upvote 0
Solution

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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
Back
Top