1

I am creating a new Internet Explorer window using VBScripta and displaying a form. I want to add images to the IE window but I'm unable to add any image. A box with a small cross appears instead. I found a similar query here at "Displaying an image in a VBScript MsgBox", but the solution provided loads the image from the net(its working) but I want it from a local folder(not working). Can some help me out with this? Thanks a lot :)

Set objIE = CreateObject("InternetExplorer.Application")  
With objIE     
 .Navigate "C:\Users\NA34242\Documents\SAP\Pages\GetTRs.html"     
 .ToolBar = False     
 .StatusBar = False     
 .Left = 100     
 .Top = 100     
 .Width = 200     
 .Height = 200     
 .Visible = True     
 .Document.Title = "Form"     
 .Document.Body.InnerHTML =  "<img src=""C:\images.png"" height=100 width=100>" 
End With 
Community
  • 1
  • 1
Antzy
  • 9
  • 2
  • 5

1 Answers1

0

I'm sorry but that approach won't work with most browser, it's a security issue, you can only use uri's for the IMG.src What you CAN do is navigate to the file itself and so make it visible, if you need other stuff on the page you will have to do it in another frame.

Here is a script of me i adopted to show an image from my locat c: drive. With the show sub you can display text but not your IMG

dim oIe
InitIE 500, 500
oIe.navigate "file:///C|/Users/peter/butterfly.png"
'--- ---'
Sub InitIE(iWidth,iHeight)
  Dim iLeft, iTop
  On error resume next
  Set oIe = WScript.CreateObject("InternetExplorer.Application", "IE_")
  If Err.Number <> 0 Then
    WScript.CreateObject("WScript.Shell").Popup("Error:" & Err.description)
    Wscript.Quit
  Else
    With oIe
      .Visible = False
      .TheaterMode = True
      .FullScreen = True
       iLeft = (.width - iWidth) / 2
       iTop = (.Height - iHeight) / 2
      .FullScreen = False
      .TheaterMode = False                            
      .MenuBar = True
      .ToolBar = False
      .StatusBar = True
      .AddressBar = False
      .navigate "about:blank"
      .Width = iWidth
      .Height = iHeight
      .Left = iLeft
      .Top = iTop
      .Resizable = True
      .Visible = True
      .document.focus()                                
    End With
  End If
End Sub
'--- ---'
Sub Show(ByVal sText)
  If IEReady() Then 
    oIe.Document.body.innerHTML = oIe.Document.body.innerHTML & sText & "<br>"
    iLengte = iLengte + 300
    oIe.Document.parentWindow.scroll 0, iLengte
  End If
End Sub
'--- ---'
Function IEReady()
  IEReady = False
  If TypeName(oIe) <> "Object" Then
    If oIe.ReadyState = 4 Then
      IEReady = True
    End If
  End If
End Function
'--- ---'
Sub CloseIE
  oIe.Quit
  Set oIe = Nothing
End Sub
peter
  • 41,770
  • 5
  • 64
  • 108