VBA, Adjust brightness and contrast

SerenityNetworks

Board Regular
Joined
Aug 13, 2009
Messages
100
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:

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

SerenityNetworks

Board Regular
Joined
Aug 13, 2009
Messages
100
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.

Code:
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:

Watch MrExcel Video

Forum statistics

Threads
1,102,867
Messages
5,489,361
Members
407,686
Latest member
Chuck1960

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top