[英]Microsoft Word: Select and GoTo InlineShape
我的 Word 文檔中的宏遍歷所有圖形(內聯形狀)並更新鏈接和值。 目前,文檔在“請稍候”表單對話框后面的整個過程中凍結。 理想情況下,我會讓代碼在整個文檔中移動,以向用戶展示實際正在發生的事情。
如何在下面的循環中 select 和轉到當前的內聯形狀?
Private Sub UpdateFields()
PleaseWait.bar.Width = 0
PleaseWait.Show
' This routine sets the new path for external links, pointing them to the current folder.
Dim Rng As Range, Fld As Field, Shp As Shape, iShp As InlineShape, i As Long
Dim no_of_steps As Integer
Dim single_step_width As Integer
no_of_steps = 0
With ThisDocument
' Create progress bar
' a) Count total number of steps
For Each Rng In .StoryRanges
For Each iShp In Rng.InlineShapes
no_of_steps = no_of_steps + 1
Next iShp
Next Rng
' b) Divide full width of progress frame by number of steps
single_step_width = PleaseWait.frame.Width \ no_of_steps
' Go through all story ranges in the document.
For Each Rng In .StoryRanges
' Go through the inlineshapes in the story range.
For Each iShp In Rng.InlineShapes
With iShp
' Skip over inlineshapes that don't have links to external files.
If Not .LinkFormat Is Nothing Then
With .LinkFormat
' Skip links already set to current folder
If Not .SourceFullName = ThisDocument.Path & "\datagrunnlag.xlsm" Then
' Replace the link to the external file
.SourceFullName = ThisDocument.Path & "\datagrunnlag.xlsm"
On Error Resume Next
.AutoUpdate = False
.Update
On Error GoTo 0
End If
End With
End If
' Update progress bar with completed step
PleaseWait.bar.Width = PleaseWait.bar.Width + single_step_width
DoEvents
End With
Next iShp
Next Rng
End With
End Sub
編輯 05.12.2020:在子目錄中添加了所有代碼。 ScreenUpdating = False 和 True 由 MacroEntry 和 MacroExit 的單獨子設置。
那將是一個非常糟糕的主意。 使用選擇 object 只會進一步減慢操作速度,並讓用戶詛咒你。
由於您似乎已經有了進度指示器,因此您正在盡一切努力讓用戶了解情況。
任何涉及滾動文檔的操作都會使您的代碼運行得更慢,因此您能做的最好的事情就是確保您的代碼在盡可能短的時間內完成。 這包括避免使用Selection
object 和關閉ScreenUpdating
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.