Displayalerts and Screenupdating

H

Hari

Hi,

Whats the difference between Application.displayalerts and
Application.screenupdating

1. In which scenarios should I use displayalerts and in which shud I use
screenupdating
2. What is the negative consequence of setting application.displayalerts to
false.
3.If I dont set application.displayalerts to true at the end of the code is
it dangerous or harmful for me?
4. I read help on Screenupdating and it said about it speeds up what the
macro does, though we will not be able to see what the macro does. I want to
know whether it has any bad effect on my coding. Like suppose my macro does
something I didnt intend to do ( I mean If I wrote the code doing an
incorrect operation),would I not get to know as help says that I will not
get to see what the macro does.(Im a absolute novice).

Regards,
Hari
India
 
H

Harald Staff

Hi Hari

Displayalerts asks the user for confirmation before deleting / overwriting /
not saving / you name it. Screenupdating creates everything you see on the
on the screen. In theory you could be asked without seeing it and everything
stops.
1. In which scenarios should I use displayalerts and in which shud I use
screenupdating

That depends on what your code is doing. But as a novice, you should not
turn off displayalerts until your code works good. You shouldn't turn off
anything until it's good.
2. What is the negative consequence of setting application.displayalerts to
false.

You won't be warned before you or your code do something you may regret, and
there is no recovery anywhereck.
3.If I dont set application.displayalerts to true at the end of the code is
it dangerous or harmful for me?

Yes (see 2). The setting itself is no danger, the real danger is you and
your code.
4. I read help on Screenupdating and it said about it speeds up what the
macro does, though we will not be able to see what the macro does. I want to
know whether it has any bad effect on my coding. Like suppose my macro does
something I didnt intend to do ( I mean If I wrote the code doing an
incorrect operation),would I not get to know as help says that I will not
get to see what the macro does.(Im a absolute novice).

If a macro is programmed to destroy something, then destroy it will. Wether
you see it happen or not will not change anything.

HTH. Best wishes Harald
 
B

Bob Phillips

Screenupdating controls the repainting of the screen, and would typically be
used when there is a loop that changes cells in the various iterations,
thereby causing many repaints. Putting ScreenUpdating = False can
dramatically improve the speed.

DisplayAlerts is used to determine whether certain system messages get
displayed or not, such as that message that pops up if you try to overwrite
an existing file. The negative effect is that you might miss a message you
want to see. VBA Help says that it is not automatically reset at the end,
but I am sure that I found that it is. Either way, it isn't much to do it
yourself.

As to negative effects of screenupdating, that is why you test it. Don't
rely on seeing something go wrong.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
H

Hari

Hi Harald and Bob,

Thanx a lot for ur replies. Im slightly more better off than in terms of
understanding than what I was before.

I posed a problem for automatic opening of excel files in a particular
folder and I got this code from William., wherein he has used Screenupdating
feature.

I want to understand what is the role of screenupdating here.

Please tell me if possible . ( I modified the interior of the code slightly
as compared to what William had given as I was getting compile error in his
code. I used help feature to make this modification)

Also, I have one more doubt in this. Presently the code says
searchsubfolders as False. For experimental purpose I changed it to true and
one of the subfolders had a excel file of the same name as in the root
folder. Inspite of this excel didnt display the message that 2 files with
same name cannot be opened.I thought this might be happeneing because of
Application.ScreenUpdating = False but as per ur explanation for
"Displayalerts and screenupdating" that would happen only if the code
mentioned about Displayalerts. Please tell me why excel doesnt display
messages for the below code.

Sub OpenWorkbooksInLocation()

Application.ScreenUpdating = False
Dim i As Integer
With Application.FileSearch
.NewSearch
.LookIn = "C:\CCAPPS\ttlview\TMP"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
.Execute
For i = 1 To .FoundFiles.Count
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
'Macro code for each workbook here
'wb.Save
'wb.Close
Next i
End With
Application.ScreenUpdating = True

End Sub


Thanx a lot
 
B

Bob Phillips

Hari,

You are missing the point completely here. The problem is nothing to do with
FileSearch, nothing to do with ScreenUpdating. The problem is simply that
you cannot open 2 workbooks with the same name, even if they are in separate
directories.

You have 2 files with the same name, one in the top-level, one in a
subdirectory. Ignoring the code, open the first in Excel. Then try to open
the second. What do you get? Exactly the same error message.

William presumably turned the Screenupdating off to stop each workbook being
opened showing as it happened and causing a lot of flickering.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top