Freeze screen when running code

zoog25

Active Member
Joined
Nov 21, 2011
Messages
418
Hello all,

Here is the situation, i have the following code that I'm running. The code moves sheets from one workbook to another and then adds VBA coding to a few of the sheets. My question is the following, is there any code that prevents a person from visually seeing the code run its parts. What i mean is that when i run the code it shows opening up the other workbook, moving the sheets over, opening the editor window, adding code to the sheets, and then closing the editor window. All might make the person running feel like there is an issues. Is there any way of say having the screen freeze and then have all the items run int he background and then when the screen unfreezes, all the changes have been made. Here is the code i'm running in case there is something i can add to it to make this happen.

VBA Code:
Sub WBOpenMod()

Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False

Dim fName
Dim wbATL As Workbook

fName = ActiveWorkbook.Path & "\Agreement Tracking Log.xlsx"

Select Case fName = Empty
    Case False
        Set wbATL = Workbooks.Open(fName)
        wbATL.Sheets("Final Map").Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
        wbATL.Sheets("Tract Parcels").Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
        wbATL.Sheets("Permits").Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
        wbATL.Sheets("NOC").Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
        wbATL.Sheets("Security").Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
        wbATL.Sheets("Contact").Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
        wbATL.Sheets("Contact (ST)").Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
        wbATL.Sheets("DATA").Move Before:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
        Call AddFMCode
        Call AddTPCode
        Call AddSTCode
        Call AddNOCCode
        wbATL.Save
        wbATL.Close
        WbOpen = True
End Select

ThisWorkbook.VBProject.VBE.MainWindow.Visible = False

Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True

End Sub

As you can see i tried using the ScreenUpdating to prevent this but it doesn't quite do what i want it to do.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
i dont know the answer, but a work around might be to display a full screen userform with a progress bar or something?
 
Upvote 0
have you set screenupdating to false in any of the macros that you call from this routine?
 
Upvote 0
Turning off ScreenUpdating will only work partially for freezing the excel window, won't work on the vbe.

You can use some API calls to freeze the entire screen but if an unhandled error occurs, it could cause the entire screen to stay frozen adding more confusion to the user.

Adding to diddi's suggestion, you could also make the userform topmost to prevent any other window from coming to the foreground.

Another idea is to open the "Agreement Tracking Log.xlsx" workbook in a hidden seperate excel instance and run the macro there.

BTW, You can add code to a vbaproject without making the vbe visible.
 
Upvote 0
Hello Jaafar,

Thank for the suggestions. I did have a question or follow up to what you said.

How do i open workbook in a hidden separate excel instance?

Seconding with you last comments, how do i add code to the project without making the vbe visible.

Thank you.
 
Upvote 0
Hi Zoog25. There are plenty of websites (and posts in this forum!) which that deal with both of your questions.

As a general guide, Chip Pearson's site is always an excellent resource , and he provides a useful guide on adding VBA code programatically (i.e., without making the VBE visible): http://www.cpearson.com/Excel/vbe.aspx. As for using separate instance, the code provided by Excel Off The Grid would help you here:

VBA Code:
Sub CreateNewSession()
Dim xlApp As Excel.Application
Set xlApp = New Excel.Application

xlApp.Workbooks.Add
xlApp.Visible = True

Set xlApp = Nothing
End Sub

To make it 'hidden', you just need to change the .Visible property to False.
 
Upvote 0
Solution
Thank you Dan_W for the advice. I believe your method works in more or less how I can do a few things. Also, the links you provided are great resources to help with other aspects I can incorporate.
 
Upvote 0
Glad to hear it - I always learn something new whenever I visit Chip's site.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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