View Single Post
 
Old 04-28-2017, 01:40 PM
Welshgasman Welshgasman is offline Windows 7 32bit Office 2003
Novice
 
Join Date: Jun 2011
Posts: 26
Welshgasman is on a distinguished road
Default Application.ScreenUpdating not working?

Hi all,
Before I start, I will admit I posted this in a forum that helps me a lot with another Office product, but as of this post they were not able to shed any light on this issue.

I created the code below which does what it was written for, BUT the screen updates whilst it runs.
The screen flickers (presumably when opening each document)?

Is there a way to suppress this.?
I was offered Appliication.Echo as a solution, but that is not recognised in Word 2007?

TIA
Code:
Sub InsertText()
Dim Shp As Shape, Doc As Document, strTextToInsert As String, strTextToFind As String
Dim i As Long, docToOpen As FileDialog, sHght As Single
Dim rngToSearch As Word.Range
Dim DataObj As New MSForms.DataObject
    
    On Error GoTo Err_Exit
    'strText = InputBox("New Text", "Header Textbox Update", "New Text")
    
    ' Switch off the updates of screen
    Application.ScreenUpdating = False
    
    ' Set the text
    strTextToInsert = "Annual bonus rates for the last five years"
    strTextToFind = "Discharge Pack"
    
    DataObj.SetText strTextToInsert
    DataObj.PutInClipboard
    
    Set docToOpen = Application.FileDialog(msoFileDialogFilePicker)
    docToOpen.Show
    For i = 1 To docToOpen.SelectedItems.Count
        'Open each document
        Set Doc = Documents.Open(FileName:=docToOpen.SelectedItems(i))
            Selection.Find.ClearFormatting
        With Selection.Find
            .Text = strTextToFind
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.TypeParagraph
        Selection.PasteAndFormat (wdListCombineWithExistingList)
        ' The above inserts a line which creates a second page, so delete a line after
        Selection.EndKey Unit:=wdStory
        Selection.Delete Unit:=wdCharacter, Count:=1

        ActiveDocument.Close SaveChanges:=wdSaveChanges
    Next
    
    Set docToOpen = Nothing: Set Doc = Nothing
    ' Switch Screen updates back on
    Application.ScreenUpdating = True
    Exit Sub
Err_Exit:
    MsgBox Err.Description & Err.Number
End Sub
Reply With Quote