Space at corner of web browser control

nightcrawler23

Well-known Member
Joined
Sep 24, 2009
Messages
721
HI all, I use the below code to load a gif on my userform using a web browser control. I have the control of the size 30x30. even if i choose a gif of size 25x25 it doesnot center on the control.
Seems like there is some extra padding or space added to the gif before loading.

Any idea how to remove this.

Code:
Private Sub UserForm_Initialize()
With wb1
    .Navigate (ThisWorkbook.Path & "/loading8.gif")
End With
End Sub

Private Sub wb1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Me.wb1.Document.Body.Scroll = "no"
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hello nightcrawler23,

The Web Browser has margins. The example below sets them so there is a little white space in the upper left corner.
Code:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
     
     With WebBrowser1.Document.Body
        .Scroll = "no"
        .Style.MarginTop = 2    'Twips
        .Style.MarginLeft = 2   'Twips
     End With
    
End Sub
 
Upvote 0
Thanks Ross,
Your code works fine.
but when i place my webcontrol navigation code in the commandbuttonm click even the scrollbars appear again.

below is the code. Any ideas?

Code:
Private Sub UserForm_Initialize()
With wb1
    .Visible = False
End With
End Sub

Private Sub wb1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
With Me.wb1.Document.Body
   .Scroll = "no"
   .Style.MarginTop = 7    'Twips
   .Style.MarginLeft = 7   'Twips
End With
End Sub

Private Sub btnRunDP_Click()

With frmRecScenario.wb1
    .Navigate (ThisWorkbook.Path & "/loading8.gif")
    .Visible = True
End With

MsgBox ("OK")
Exit Sub

'/// rest of code////
 
Upvote 0
Hello nightcrawler23,

I think you should leave the Web Browser control settings in the UserForm. Why did you move them to the button?
 
Upvote 0
Hello nightcrawler23,

Maybe I misunderstand where you have this button. Is it on the UserForm or a worksheet?
 
Upvote 0
Hello nightcrawler23,

I added a button to my UserForm to load a file into the Web Browser control and it works fine. Here is the code that I used in my form. Basically, it is the same as yours, with the exception of the Initalize event.
Code:
Private Sub CommandButton1_Click()

    Filename = "C:\Documents and Settings\Admin.ADMINS\My Documents\Scales White 24.ico"
    WebBrowser1.Navigate Filename

End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
     
     With WebBrowser1.Document.Body
        .Scroll = "no"
        .Style.MarginTop = 2    'Twips
        .Style.MarginLeft = 2   'Twips
     End With
    
End Sub
 
Upvote 0
Your code is fine. the problem i am having now is to keep the gif running while my code is being executed. I have used doEvents both in the userform initialize and the btn_Click events. but that doesnt work.

I am looking for a way. Plz suggest something if you have one.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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