VBA - Change Pictures Brightness, contrast and sharpness

hibernian3

New Member
Joined
May 2, 2019
Messages
7
Hi All,

I am adding pictures into excel VBA but can't seem to figure out how to adjust the brightness, contrast and sharpness. Below code works fine except for the brightness adjustment...

VBA Code:
Sub Photoload()

Dim FldrPicker As FileDialog
Dim myFolder As String
Dim pic As Picture




Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)

  With FldrPicker
    .Title = "Select A Target Folder"
    .AllowMultiSelect = False
    If .Show <> -1 Then Exit Sub 'Check if user clicked cancel button
    myFolder = .SelectedItems(1) & "\"
  End With

Set pic = ActiveSheet.Pictures.Insert(myFolder & "/hole1.png")

With pic
.Height = 440
.Top = Range("H18").Top + (Range("H18").Height - .Height) / 2
.Left = Range("H18").Left + (Range("H18").Width - .Width) / 2
.PictureFormat.IncrementBrightness 0.3

End With

pic.ShapeRange.SoftEdge.Radius = 8

End Sub
 
What is the initial brightness set as? You can't implement it past 1.0
 
Upvote 0
Hi All,

I am adding pictures into excel VBA but can't seem to figure out how to adjust the brightness, contrast and sharpness. Below code works fine except for the brightness adjustment...

VBA Code:
Sub Photoload()

Dim FldrPicker As FileDialog
Dim myFolder As String
Dim pic As Picture




Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)

  With FldrPicker
    .Title = "Select A Target Folder"
    .AllowMultiSelect = False
    If .Show <> -1 Then Exit Sub 'Check if user clicked cancel button
    myFolder = .SelectedItems(1) & "\"
  End With

Set pic = ActiveSheet.Pictures.Insert(myFolder & "/hole1.png")

With pic
.Height = 440
.Top = Range("H18").Top + (Range("H18").Height - .Height) / 2
.Left = Range("H18").Left + (Range("H18").Width - .Width) / 2
.PictureFormat.IncrementBrightness 0.3

End With

pic.ShapeRange.SoftEdge.Radius = 8

End Sub
When they are inserted they just show as 0%, I'm then trying to change it to 10%
 
Upvote 0
When they are inserted they just show as 0%, I'm then trying to change it to 10%
If you are on about the slider showing 0% then that is the adjustment value not the actual total brightness

If it is the only picture/shape on the sheet trying running the code below and then post what it says in the immediate window

VBA Code:
Debug.Print ActiveSheet.Shapes(1).PictureFormat.Brightness
 
Upvote 0
If you are on about the slider showing 0% then that is the adjustment value not the actual total brightness

If it is the only picture/shape on the sheet trying running the code below and then post what it says in the immediate window

VBA Code:
Debug.Print ActiveSheet.Shapes(1).PictureFormat.Brightness
it is the only picture on the sheet, but i get an error saying "This member can only be accessed for a picture or OLE object"?

Its picture saved as PNG file which is currently inserted
 
Upvote 0
Thats it sorted, managed to fix by using below codes
VBA Code:
pic.ShapeRange.SoftEdge.Radius = 8
pic.ShapeRange.PictureFormat.Brightness = 0.53
pic.ShapeRange.PictureFormat.Contrast = 0.63
pic.ShapeRange.PictureFormat.sharpness = 0.63
 
Upvote 0

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