VBA, Adjust brightness and contrast

SerenityNetworks

Board Regular
Joined
Aug 13, 2009
Messages
131
Office Version
  1. 365
Platform
  1. Windows
I'm using several instances of the Private Function code below to display multiple images within an Excel form. It works fine. but I need to be able to adjust the brightness and contrast of the image displayed in each of the web containers. In the past, I've displayed images directly on a worksheet, then used the following code to change the contrast (and similarly for brightness). But I'm not figuring out how to do it for the images in the web containers. I could really use some help. (Note: I'm a hobbyist, not a coder. My VBA skills are limited.)

Thanks in advance,
Andrew

Code:
Sub SetContrast()
    Dim shape As Excel.shape
    Dim cnt As Long
    cnt = 0
    For Each shape In ActiveSheet.Shapes
        If shape.Type = msoLinkedPicture Then
            shape.PictureFormat.Contrast = gvarGlobalContrast
        End If
    Next shape
End Sub

Code:
Private Function fnCreateHTML1(strImgFilePath As String)
'//-----------------------------------------
'// Author    : "Ivan F Moala"
'// Site      : "http://www.xcelfiles.com"
'-------------------------------------------
Dim hdl As Long, m_Width1 As Long, m_Height1 As Long
Dim strAp1 As String

strAp1 = Chr(34)
m_Width1 = WebBrowser1.Width * HWF1    'WebBrowser1.Width * 1.325 is ratio of 96 / 72
m_Height1 = WebBrowser1.Height * HWF1
hdl = FreeFile

    Open strPath & "Tmp1.html" For Output As [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] 
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , ""
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , "<center>"
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , "******"
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , "Scroll = ""YES"""
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , "LEFTMARGIN=0"
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , "TOPMARGIN=0"
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , ""
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , "[IMG]https://www.mrexcel.com/forum/ & strAp1 & picURL1 & strAp1 & _<br />                     [/IMG]                    " height=" & m_Height1 & _
                    " border="0">"
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , "</center>"
        Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hdl"]#hdl[/URL] , ""
    Close hdl
End Function
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I just noticed that my pasted code for the web container chopped out code. I'm pasting it again using php tags. It's pasting cleanly now.

PHP:
Private Function fnCreateHTML1(strImgFilePath As String)
'// Using this code, the images will be loaded and stretched to fit "full-screen" into the form's browser window.
'//-----------------------------------------
'// Author    : "Ivan F Moala"
'// Site      : "http://www.xcelfiles.com"
'-------------------------------------------
Dim hdl As Long, m_Width1 As Long, m_Height1 As Long
Dim strAp1 As String

strAp1 = Chr(34)
m_Width1 = WebBrowser1.Width * HWF1    'WebBrowser1.Width * 1.325 is ratio of 96 / 72
m_Height1 = WebBrowser1.Height * HWF1
hdl = FreeFile

    Open strPath & "Tmp1.html" For Output As #hdl
        Print #hdl, "<HTML>"
        Print #hdl, "<CENTER>"
        Print #hdl, "******"
        Print #hdl, "Scroll = ""YES"""
        Print #hdl, "LEFTMARGIN=0"
        Print #hdl, "TOPMARGIN=0"
        Print #hdl, "</BODY>"
        Print #hdl, "<IMG width= " & m_Width1 & _
                    " height= " & m_Height1 & _
                    " SRC = " & strAp1 & picURL1 & strAp1 & _
                    "; Border = 0>"
        Print #hdl, "</CENTER>"
        Print #hdl, "</HTML>"
    Close hdl
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,136
Members
448,551
Latest member
Sienna de Souza

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