Displaying animated GIF on another userform while macro runs

Broker666

New Member
Joined
Jun 8, 2013
Messages
7
Hi,

Basically I have a main userform called 'Main' that contains a number of command buttons to run specific macros. I also have another userform called 'Loading' that contains a WebBrowser Control that houses an animated GIF. What I want to achieve is click one of the command buttons on the main form, launch the additional form containing the animated gif and then close this form upon completion of the macro. I have opened both forms as non modal and the loading userform is displayed but there is a white screen where the animated gif should be. I am thinking that it will probably involve DoEvents or Repaint but I'm not quite sure where to include it in the code. Any help would be massively appreciated.


On click event of command button on main form

Private Sub CommandButton1_Click()

Loading.Show vbModeless

Application.Run "Macro1"

Unload Loading

End sub


Code contained within the Loading form:

Private Sub UserForm_Activate()

Call RemoveCaption(Me)
WebBrowser1.Navigate ("C:\Users\B666\Images\31.gif")

End Sub


Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Me.WebBrowser1.Document.body.Scroll = "no"
WebBrowser1.Document.body.Style.Border = "none"
WebBrowser1.Visible = True
Me.Repaint

End Sub


Code in workbook module to remove caption from 2nd userform


Sub RemoveCaption(objForm As Object)

Dim lStyle As Long
Dim hMenu As Long
Dim mhWndForm As Long

If Val(Application.Version) < 9 Then
mhWndForm = FindWindow("ThunderXFrame", objForm.Caption) 'XL97
Else
mhWndForm = FindWindow("ThunderDFrame", objForm.Caption) 'XL2000+
End If
lStyle = GetWindowLong(mhWndForm, -16)
lStyle = lStyle And Not &HC00000
SetWindowLong mhWndForm, -16, lStyle
DrawMenuBar mhWndForm

End Sub


Regards,

B666.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Here is how I got it to work. Both forms need to be loaded Modeless. And you will need a DoEvents to allow the forms and Macro1 to run at the same time.

For testing, Macro1 is in a module and will display a message box.

Load the first user form:
Rich (BB code):
Private Sub Main()
   Load UserForm1
   UserForm1.Show vbModeless
End Sub

Command Button Code- UserForm1
Rich (BB code):
Private Sub CommandButton1_Click()
   Load UserForm2
   UserForm2.Show vbModeless
   
   DoEvents
   Application.Run "Macro1"
   
   Unload UserForm2
End Sub

UserForm2 - WebBrowser Initialize Event
Rich (BB code):
Private Sub UserForm_Initialize()
   Me.WebBrowser1.Navigate ("C:\temp\couple5.gif")
End Sub
 
Upvote 0
I have a slight problem. I have a macro that runs on workbook open that set the application.visible property to false and loads the main form. However when I altered the code to load the main form as modeless rather than modal the workbook is visible behind the main userform. When I load the main form as modal then the workbook is hidden as expected. Any suggestions?
 
Upvote 0
In all honesty this is not something I have ever tried to do before. My initial thoughts are the error handling techniques to restore the application before close. Also, if the code produces an error how do you edit it with the application hidden?

I did a Google search and found relevant information in the link below.
Pay attention to post #7
Post #5 contains the code you can experiment with.
Hide Excel & Only Show a UserForm
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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