How do I to format fill for a picture using VBA?

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
855
Office Version
  1. 365
Platform
  1. Windows
I have code below. It copies some cells in one worksheet (Inputs), then pastes them as a picture into another worksheet (Report). It is transparent after the paste but I want it to not be transparent and I want it to have fill of white. I tried approaches that I could think of but get "Object does not support this property or method" error. What basic concept/syntax am I missing?

VBA Code:
Sub PictureOfTopToReport()

    Dim wsInput As Worksheet
    
    Dim wsReport As Worksheet
    
    Dim picTop As Picture
    
    Dim sPicTopName As String
    
    Set wsInput = Worksheets("Inputs")
    
    Set wsReport = Worksheets("Report")
    
    sPicTopName = "TopPart"
    
    wsInput.Range("A1:AK19").Copy
    
    With wsReport
        .Activate
        .Range("A1").Activate
        Set picTop = .Pictures.Paste
        picTop.Name = sPicTopName
    End With
    
    Application.CutCopyMode = False
    
'   Code below causes "Object does not support this property or method" errors
    With picTop
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorBackground1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
        .Solid
    End With

    With wsReport.Shapes(picTop.Name)
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorBackground1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
        .Solid
    End With

End Sub
 

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)
Here is the syntax to set fill for a picture

VBA Code:
    With wsReport.Shapes.Range(Array(sPicTopName))
        .Visible = msoTrue
        With .Fill
            .ForeColor.ObjectThemeColor = msoThemeColorBackground1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = 0
            .Transparency = 0
            .Solid
        End With
    End With
 
Upvote 0
Try:

VBA Code:
Sub PictureOfTopToReport()
  Dim wsInput As Worksheet, wsReport As Worksheet
  Dim picTop As Picture
  Dim sPicTopName As String
  
  Set wsInput = Worksheets("Inputs")
  Set wsReport = Worksheets("Report")
  
  sPicTopName = "TopPart"
  wsInput.Range("A1:AK19").Copy
  
  With wsReport
    .Activate
    .Range("A1").Activate
    Set picTop = .Pictures.Paste
    picTop.Name = sPicTopName
  End With
  
  Application.CutCopyMode = False
  
  With picTop.ShapeRange.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(255, 255, 255)     'white
    .Transparency = 0
  End With
End Sub
 
Upvote 0
Solution
DanteAmor: I figured that out after my last post. Thank you for the assist!

VBA Code:
    With picTop.ShapeRange
        .Visible = msoTrue
        With .Fill
            .ForeColor.ObjectThemeColor = msoThemeColorBackground1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = 0
            .Transparency = 0
            .Solid
        End With
    End With
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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