Vba word отключить обновление экрана

title keywords f1_keywords ms.prod api_name ms.assetid ms.date ms.localizationpriority

Application.ScreenUpdating property (Word)

vbawd10.chm158335002

vbawd10.chm158335002

word

Word.Application.ScreenUpdating

660284d1-2b00-eba0-28bc-36bc6400fcf4

06/08/2017

medium

Application.ScreenUpdating property (Word)

True if screen updating is turned on. Read/write Boolean.

Syntax

expression.ScreenUpdating

expression An expression that returns an Application object.

Remarks

The ScreenUpdating property controls most display changes on the monitor while a procedure is running. When screen updating is turned off, toolbars remain visible and Word still allows the procedure to display or retrieve information using status bar prompts, input boxes, dialog boxes, and message boxes. You can increase the speed of some procedures by keeping screen updating turned off. You must set the ScreenUpdating property to True when the procedure finishes or when it stops after an error.

Example

This example turns off screen updating and then adds a new document. Five hundred lines of text are added to the document. At every fiftieth line, the macro selects the line and refreshes the screen.

Application.ScreenUpdating = False 
Documents.Add 
For x = 1 To 500 
 With ActiveDocument.Content 
 .InsertAfter "This is line " & x & "." 
 .InsertParagraphAfter 
 End With 
If x Mod 50 = 0 Then 
 ActiveDocument.Paragraphs(x).Range.Select 
 Application.ScreenRefresh 
End If 
Next x 
Application.ScreenUpdating = True

See also

Application Object

[!includeSupport and feedback]

I’ve got a word 2013 macro which is taking quite some time to finish.

The macro is reformatting the document and the Screen keeps updating while the macro is running, which I guess is where word spends most of it’s time.

How can I disable screen updating in word in a macro and refresh it when the macro is finished?

Kazimierz Jawor's user avatar

asked Jul 16, 2013 at 7:04

Sam's user avatar

Try with adding this line at the beginning of your code:

Application.ScreenUpdating = False

and this at the end:

Application.ScreenUpdating = True

If this doesn’t help you need to add more information and possibly post your code.

answered Jul 16, 2013 at 7:17

Kazimierz Jawor's user avatar

Kazimierz JaworKazimierz Jawor

18.8k7 gold badges35 silver badges55 bronze badges

1

title keywords f1_keywords ms.prod api_name ms.assetid ms.date ms.localizationpriority

Application.ScreenRefresh method (Word)

vbawd10.chm158335277

vbawd10.chm158335277

word

Word.Application.ScreenRefresh

303db23c-492c-5e33-0363-7ef6433dc90e

06/08/2017

medium

Application.ScreenRefresh method (Word)

Updates the display on the monitor with the current information in the video memory buffer.

Syntax

expression.ScreenRefresh

expression Required. A variable that represents an Application object.

Remarks

Use this method after using the ScreenUpdating property to disable screen updates. ScreenRefresh turns on screen updating for just one instruction and then immediately turns it off. Subsequent instructions don’t update the screen until screen updating is turned on again with the ScreenUpdating property.

Example

This example turns off screen updating, opens Test.doc, inserts text, refreshes the screen, and then closes the document (with changes saved).

Dim rngTemp As Range 
 
ScreenUpdating = False 
Documents.Open FileName:="C:DOCSTEST.DOC" 
 
Set rngTemp = ActiveDocument.Range(Start:=0, End:=0) 
 
rngTemp.InsertBefore "new" 
Application.ScreenRefresh 
ActiveDocument.Close SaveChanges:=wdSaveChanges 
ScreenUpdating = True

See also

Application Object

[!includeSupport and feedback]

Return to VBA Code Examples

In this Article

  • Disable ScreenUpdating
  • Enable ScreenUpdating
  • VBA ScreenUpdating Example
  • ScreenUpdating Refresh
    • VBA Settings – Speed Up Code
  • VBA Coding Made Easy

As cool as it looks watching your VBA macro manipulate the screen, you can help your Macro run faster if you turn off (disable) ScreenUpdating.

Disable ScreenUpdating

1. To disable ScreenUpdating, At the beginning of your code put this line:

Application.ScreenUpdating = False

Enable ScreenUpdating

2. To re-enable ScreenUpdating, At the end of your code put this line:

Application.ScreenUpdating = True

VBA ScreenUpdating Example

Your procedure will then look like this:

Sub ScreenUpdating_Example()
    Application.ScreenUpdating = False

    'Do Something
    Range("a1").Copy Range("b1")
    Range("a2").Copy Range("b2")
    Range("a3").Copy Range("b3")


    Application.ScreenUpdating = True
End Sub

vba screen updating

ScreenUpdating Refresh

Disabling ScreenUpdating will make your VBA code run MUCH faster, but it will also make your work appear more professional. End-users typically don’t want to see the behind the scenes actions of your procedures (especially when the procedure runs slow). Also, you may not want end-users to see the behind the scenes functionality (ex. Hidden Worksheets). I recommend disabling (and re-enabling) ScreenUpdating in virtually all of your procedures.

However, there are some times when you want the screen to refresh. To refresh the screen, you will need to temporarily turn back on ScreenUpdating (there is no screen “refresh” command):

    Application.ScreenUpdating = True
    'Do Something
    Application.ScreenUpdating = False

VBA Settings – Speed Up Code

There are several other settings to play with to improve your code speed.

Disabling Automatic Calculations can make a HUGE difference in speed:

Application.Calculation = xlManual

Disabling the Status Bar will also make a small difference:

Application.DisplayStatusBar = False

If your workbook contains events you should usually disable events at the beginning of your procedure:

Application.EnableEvents = False

Last, your VBA code can be slowed down when Excel tries to re-calculate page breaks (Note: not all procedures will be impacted).  To disable displaying page breaks use this line of code:

ActiveSheet.DisplayPageBreaks = False

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

VBA Turn Off On ScreenUpdating

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro — A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!
vba save as

Learn More!

Please Note:
This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Turning Off Screen Updating.

Written by Allen Wyatt (last updated August 19, 2020)
This tip applies to Word 97, 2000, 2002, and 2003


Many people write their own macros to manipulate their documents. Many times the macro may do quite a bit with the document, such as jumping to different places, replacing text, and taking other types of actions. This means that the Word screen can look like it has «gone crazy» while the macro is running.

One thing you may want to do with your macro to make it run faster and to prevent distracting flashes on the screen is to turn off screen updating while the macro is running. The following macro lines will, respectively, turn off screen updating and then turn it back on in a VBA macro.

Application.ScreenUpdating = False
Application.ScreenUpdating = True

The idea is to use the first line near the beginning of your macro, and then use the second line near the end. Thus, the main body of your macro can do its work behind the scenes without the necessity of stopping to update the screen.

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I’ve prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training.
(Microsoft Word is the most popular word processing software in the world.)
This tip (749) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Turning Off Screen Updating.

Author Bio

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. Learn more about Allen…

MORE FROM ALLEN

Default Numbering Format for Endnotes

The default format for endnote numbers is lowercase Roman numerals. If you want the numbers to use a different format, …

Discover More

Trouble Recording Paste Special Formula

Sometimes, when you upgrade to a new version of Excel, you could run into a problem recording macros that you had no …

Discover More

Transferring Ribbon Customizations

Excel allows you to make a wide range of customizations to both the Quick Access Toolbar and the ribbon. If you want to …

Discover More

More WordTips (menu)

Determining if a File Exists

Your macro may need to know if a particular file exists. This is easy to figure out using the Dir command, and even …

Discover More

Printing the Active Document from a Macro

When you process a document in a macro, you may also want to print that document from within the same macro. Here’s how …

Discover More

Determining a Paragraph’s Style in VBA

When processing a document via a macro, it is often helpful to understand what style has been applied to a paragraph. You …

Discover More

Студворк — интернет-сервис помощи студентам

Добрый день!

Сразу скажу — про режим отключения обновления экрана при работе vba-скрипта знаю и прочитал про него достаточно много.
Но!

Есть Word 2010, в документе docm имеется небольшая форма, нажатие кнопки на которой запускает некий скрипт (во время выполнения скрипта форма остается открытой).
Этот скрипт в цикле:
— создает новый документ
— цикл по документам в заданной папке
— открывает word-документ
— выделяет в нем содержимое нужной страницы
— копирует выделение в буфер обмена
— закрывает word-документ
— вставляет буфер обмена в текущую позицию документа, созданного в начале основного цикла
— вставляет пустой параграф
— сохраняет созданный документ под нужным именем

Основная проблема — документов много из-за чего экран мигает как бешенный и, соответственно, скорость небольшая.
Попытался выключить обновление экрана ScreenUpdating=False.
Мигание не прекратилось — теперь открываемые окна пустые (т.е., просто не прорисовываются события в этих окнах), но все равно все мигает и медленно.
Главная проблема в этом режиме — неверно отрабатывает скрипт!
Т.е., вместо выделения одной страницы документа выделяются ВСЕ страницы от нужной и до конца документа!
К примеру, если в документе 10 страниц и нужно выделить только страницу 5, то в режиме ScreenUpdating=False выделяются страницы с 5 по 10!

В общем, вопрос — есть РЕАЛЬНЫЙ способ ПОЛНОСТЬЮ отключить все это мигание или вообще временно скрыть Word и все его окна?!
И второй вопрос — почему в режиме ScreenUpdating=False некорректно работает выделение нужной страницы и как это исправить?

Упрощенный код основного цикла скрипта:

Visual Basic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ChangeFileOpenDirectory WorkPath
' Создаем 10 билетов
For Card = 1 To 10
   ' Создаем новый билет
   Documents.Add
   ' Цикл по документам из папки WorkPath
   For Task = 1 To 18
      ' Открываем документ с заданиями
      Documents.Open "mat-08_A" & Format(Task, "00") & ".doc"
      ' Определяем номер нужной страницы
      Page = ...
      ' Переходим к нужной странице и копируем ее содержимое в буфер обмена
      Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=Page
      ActiveDocument.Bookmarks("page").Range.Copy
      ActiveDocument.Close
      ' Вставляем содержимое буфера обмена и пустой параграф в билет
      Selection.PasteAndFormat (wdFormatOriginalFormatting)
      Selection.TypeParagraph
   Next
   ' Сохраняем сформированный билет и закрываем его
   ActiveDocument.SaveAs FileName:=TicketsPath & CardDocPre & "-" & Format(Card, "00") & ".doc"
   ActiveDocument.Close
Next

Спасибо!

Home / VBA / VBA ScreenUpdating | How to Turn it ON and OFF

What is VBA Screen Updating?

ScreenUpdating is a property in VBA that you can use to turn “ON” and “OFF” the screen updating while running the code. You can turn it off before running a code that makes your code run faster and then turn it on once the execution of the code completes. You can read and write this property.

By default, screen updating is “ON” in Excel. When you normally run a code it takes a lot of flickering if that code takes time, but if you turn OFF the screen updating it will take less time than normal to run.

Turn OFF Screen Updating in VBA

  1. First, type the keyword “Application”.
  2. After that, press a dot “.” to open the properties and methods list.
  3. Now, select “ScreenUpdating”.
  4. In the end, specify “False” to it.

Once you turn off screen updating, VBA will not turn it ON once the code is executed. So it’s always better to turn it off from your end. The code would be like something below.

Points to Consider

  • Make sure to have the screen updating “ON” when you are using a user form.
  • If you are debugging code, it is better to have a screen updating “ON” so that you can see all the activities as they are.

There’s More

VBA With Statement | VBA Wait and Sleep Commands | VBA Status Bar | VBA Random Number | Line Break in a VBA Code | VBA Immediate Window (Debug.Print) | VBA Concatenate | VBA Module | VBA Random Number

Like this post? Please share to your friends:
  • Vba word объект надпись
  • Vba word объект application
  • Vba word работа с файлами
  • Vba word объединение ячеек таблицы
  • Vba word примеры кода