Monday, March 14, 2016

How to check the size of a picture in bytes in EXCEL VBA

To check the size in bytes of your pictures, use the "FileLen()" function of VBA:

Sub Check_pic_size(mypic)
Set mypic = ActiveSheet.Shapes.AddPicture(pp, msoFalse, msoTrue, ActiveCell.Left, ActiveCell.Top, -1, -1)

If FileLen(pp) > 100000 Then
     MsgBox ("The size of your file is too big, please reduce to 100,000 bytes. Current size is " &      FileLen(pp) & " bytes.")
     mypic.Delete
     Exit Sub
End If
End Sub



Created by DoMyExcel.com © | Excel & VBA Consulting | Customized Excel Solutions starting at 29 USD
Services provided to Individuals and Businesses | Free Quote: DoMyExcel@gmail.com

No comments:

Post a Comment