我們為了大量更新 Office 文件內容,加速更新速度的方式,就是修改 Application.ScreenUpdating = False
因為你每做一個指令,就會造成畫面更新,如果你的文件有上千頁,速度就會被拖的很慢,所以最快的方式就是先通知 Office 先不要更新畫面,等做完再更新!
Sub 刪除文件中所有圖片()
'
' 範例:刪除文件中所有圖片
'
'
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^g"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Wend
Application.ScreenRefresh
Application.ScreenUpdating = True
End Sub