pranjalgoku
pranjalgoku

Reputation: 39

How to apply border to images inserted as Picture elements (Dim var as Picture) in Excel sheet using VBA?

I want to apply border to images inserted in the excel sheet using the variable: Dim Pic as Picture from local directory (After downloading it there.)

I have tried to search many websites for help online but no help so far as most of them are for Shape variable and not for Picture variable.

Do I have to use shape variable as well or is there a way to apply the border as when I type "Pic." then I can see the option of Pic.border available but I don't know how to use it. Please help regarding this.

.....
URLDownloadToFile 0, imgsrc, dlpath & code + ".jpg", 0, 0

Dim PicPath As String, Pic As Picture, ImageCell As Range

PicPath = dlpath & unique_code & ".jpg"

Set ImageCell = Cells(i, "C").MergeArea

Set Pic = ActiveSheet.Pictures.Insert(PicPath)
Rows(i).RowHeight = 160

With Pic
    .ShapeRange.LockAspectRatio = msoTrue
    .Left = ImageCell.Left
    .Top = ImageCell.Top
    .Width = ImageCell.Width
    .Height = ImageCell.Height
End With
.....

Need to apply border to these images.

I want to enclose the pictures with thin borders. As of now they are covering the borders of the cell they are part

Upvotes: 0

Views: 2507

Answers (1)

AAA
AAA

Reputation: 3670

To add a border of, say width 1, amend your With code section as follows:

With Pic
    .ShapeRange.LockAspectRatio = msoTrue
    With .ShapeRange.Line
        .Visible = msoTrue
        .Weight = 1
    End With
    .Left = ImageCell.Left
    .Top = ImageCell.Top
    .Width = ImageCell.Width
    .Height = ImageCell.Height
End With

You can add any other border parameters within the nested With.

Upvotes: 1

Related Questions