![]() |
|
#1
|
|||
|
|||
|
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
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
What application to use?
|
pfergy | Office | 1 | 03-12-2011 08:46 PM |
| Application.FileSearch | cksm4 | Word VBA | 0 | 08-19-2010 02:18 PM |
Best application to use?
|
FrankW | Office | 2 | 06-13-2009 01:16 AM |
| What is Application Automation and How can I use it in VBA | KramerJ | Excel | 0 | 03-30-2009 12:59 PM |
| Application.Caller | pankajkankaria | Excel | 0 | 03-18-2009 11:48 AM |