Automatically blank a worksheet on startup

phg

Board Regular
Joined
Jul 4, 2007
Messages
81
I have a spreadsheet which has a macro that runs on workbook open. It does a web query to update data. What I want to do is blank the screen (I change the text to white on white) while the query is running so the user is not confused by the old data and then change the updated text back to normal colours after the query is complete.

However on startup the spreadsheet displays normally for a second or two before it is blanked.

Is there any way to run the macro before anyting is displayed?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Try clearing the contents of the page before refreshing the query
Code:
sheets("sheet1").Cells.ClearContents

now your query code
 
Upvote 0

phg

Board Regular
Joined
Jul 4, 2007
Messages
81
I want to keep the data there in case the query fails. I then display tohe old data with a warning.

Also the ClearContents still takes a second or two to clear the screen
 
Upvote 0

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
How about having a different sheet selected, then turn screenupdating off then refresh the query...

Code:
sheets("sheet2").Select
Application.Screenupdating = false

Query code here

sheets("querysheet").Select
Application.Screenupdating = true
 
Upvote 0

phg

Board Regular
Joined
Jul 4, 2007
Messages
81
Starting from a different sheet works except I would like to allow the user to save the workbook (so they have the most recent data in case the query fails). Then when they open the workbook next they will be starting from the data sheet or wherever they were when they saved.

I tried using a BeforeClose event to blank the data but the blanking occurs before the prompt to save but it is disconcerting since it looks to the user like they are saving a blank sheet.
 
Upvote 0

phg

Board Regular
Joined
Jul 4, 2007
Messages
81
I have finally come up with a solution that almost works for me.

I have added a BeforecCose event to the worksheet. The first step is to minimize the window and then do the blanking so the user does not see the spreadsheet being set up. Then when the user opens the spreadsheet the next time the display starts already blanked.


Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
         Workbooks("test.xls").Windows(1).WindowState = xlMinimized
         Workbooks("test.xls").Activate
         Position_Default(True) 'routine which blanks the display and
                                ' puts the minimized window where you want it
End Sub

My problem now is that if the user cancels the close the spreadsheet has the display blanked and the window minimized. Any suggestions as to how the program can recognize that the close was canceled so I can restore the window and unblank the display?
 
Upvote 0

Forum statistics

Threads
1,191,587
Messages
5,987,512
Members
440,098
Latest member
MickyMouse123

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
Top