|
本帖最后由 youzhenhappy 于 2018-11-29 08:44 编辑
Word VBA 如何在程序运行过程中通过判断鼠标双击事件结束运行?
自己写了一段代码,但是担心进入死循环,所以想通过判断鼠标双击事件结束运行。请各位大佬支支招。
Sub TranslationInParagraphs()
Dim Paragh As Paragraph
Dim Paraghs() As String
Dim i As Long
ReDim Paraghs(1 To 1)
i = 0
For Each Paragh In Selection.Paragraphs
i = i + 1
ReDim Preserve Paraghs(1 To i)
Paraghs(i) = Paragh.Range.Text
Next
If UBound(Paraghs) = 1 And Paraghs(1) = "" Then End
i = 1
For Each Paragh In ActiveDocument.Paragraphs
If Paragh.Range.Text = Chr(10) Or Paragh.Range.Text = Chr(13) Then
i = i + 1
GoTo LContinue
End If
If i > UBound(Paraghs) Then GoTo LEnd
Selection.Start = Paragh.Range.Start
Selection.End = Paragh.Range.End - 1
If Left(Selection.Text, Len(Selection.Text) - 1) = Left(Paraghs(i), Len(Paraghs(i)) - 2) Then
Selection.Copy
Selection.Start = Paragh.Range.End - 1
Star = Selection.Start
keybd_event 192, 0, 0, 0 '~按下
keybd_event 192, 0, 2, 0 '~抬起
DoEvents
While Star = Selection.Start ' 主要是担心这块进入死循环
DoEvents ' 主要是担心这块进入死循环
Wend ' 主要是担心这块进入死循环
i = i + 1
End If
LContinue:
Next
LEnd:
End Sub
|
|