LoginSignup
0
0

VBA WebBrowserで画像サイズ調整

Posted at

いまさら、VBA WebBrowserですが、画像表示する際に自動サイズ調整する方法が、なかなか見つからなかったので、メモ書き

Private Sub CommandButton1_Click()

img = "画像のアドレス"

WebBrowser1.Navigate img

End Sub

これと別に、下記のルーチンを追加しおくと、WebBrowser1内の画像サイズが自動調整される

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
'画像サイズ調整

Dim a As Double
Dim b As Double

With WebBrowser1.Document.body.Style
    .BorderStyle = "none"
    .margin = "0px"
    .overflow = "hidden"
    .Background = "buttonface"
End With

a = WebBrowser1.Document.body.ClientHeight / WebBrowser1.Document.Images(0).Height
b = WebBrowser1.Document.body.ClientWidth / WebBrowser1.Document.Images(0).Width

If a < b Then
    WebBrowser1.Document.Images(0).runtimeStyle.Zoom = a
Else
    WebBrowser1.Document.Images(0).runtimeStyle.Zoom = b
End If

End Sub

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0