Remove picture from textbox

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Remove picture from textbox

Post by YasserKhalil »

Hello everyone
The following code fills the textbox with a picture

Code: Select all

Sub ShapePicture()
    Dim xSh As Shape
    Dim xPic As IPictureDisp
    Dim xFileName As String
    xFileName = ThisWorkbook.Path & "\Sample.jpg"
    Set xPic = LoadPicture(xFileName)
    Set xSh = Sheets("Sheet1").Shapes(1)
    xSh.Height = xPic.Height / xPic.Width * xSh.Width
    Set xPic = LoadPicture("")
    Set xPic = Nothing
    'xSh.Fill.UserPicture xlNone
    xSh.Fill.UserPicture xFileName
     'xPic.TextureTile = msoFalse
    'xPic.Fill.Solid
End Sub
How to remove the picture ..? I tried using xlNone but doesn't work. I even tried to send an empty string but this doesn't remove the picture and I got error.

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Remove picture from textbox

Post by HansV »

Instead of

xPic.Fill.Solid

use

xSh.Fill.Solid
Best wishes,
Hans

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Re: Remove picture from textbox

Post by YasserKhalil »

Thanks a lot, my tutor. That was unnoticeable at all.

Is there a way to check if the textbox is filled or not?

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Remove picture from textbox

Post by HansV »

The Fill.Type property of the textbox shape tells you what kind of fill the text box has. See MsoFillType enumeration (Office) for the possible values. For example, if xSh.Fill.Type = 6, the text box is filled with a picture; if it is 1, the text box has a solid color.
Best wishes,
Hans

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Re: Remove picture from textbox

Post by YasserKhalil »

Thanks a lot for your great support.
Best and Kind Regards