Forum Discussion
EXCEL - WEBBROWSER FIT IMAGE SIZE
Hi, there a way to fit the image into the webbrowser?
This is the code:
Private Sub ListBox1_Change()
Dim LTBL As ListObject
Set LTBL = Planilha1.Range("Tabela1").ListObject
WebBrowser1.Navigate ListBox1.Column(39)
End Sub
Excel 365
Windows 10
System 64
1 Reply
- SethGonzalezIron Contributor
1. Quick adjustment method
Right-click the WebBrowser control → Properties
Modify the key parameters:
ScrollBars = 0 (no scrollbars)
ScrollWidth = 100%
ScrollHeight = 100%
2. VBA autoscaling code
Dynamic scaling script:
vba
Private Sub Worksheet_Activate()
With Me.WebBrowser1
.Object.Document.Body.Style = “zoom:85%; margin:0; padding:0;”
Object.Document.Body.Scroll = “no”
End With
End Sub
(Macros need to be enabled, press Alt+F11 to insert code)
3. HTML content optimization
Force responsive layout:
Add <meta> tags to the loaded HTML:
html
<meta name=“viewport” content=“width=device-width, initial-scale=1.0”>
Run the HTML
and control it with CSS:
css
img { max-width: 100%; height: auto; }
4. Alternatives
Use Power Query to fetch web content:
Data → Get Data → From Other Sources → From Web
Right click on the image after importing → choose “Fit to cell”
Office JS API (online version of Excel):
javascript
Office.context.document.setSelectedDataAsync(htmlContent, {coercionType: “html”});